Vai al contenuto

RISOLTO: Gestire più tableview


Messaggi raccomandati

Ciao a tutti, all'interno di una view ho tre tableview che dovranno contenere informazioni diverse.

Ho notato impostando le informazioni di header e una valore fittizio sulla prima table queste vengono riportate sulle altre due; evitando la presentazione della prima table le altre due si presentano senza header e senza dati, pur in presenza delle istruzione per inserire dei valori.

Il codice è stato generato da un'applicazione per iPhone che permette il disegno di una applicazione e la generazione del codice.

Di seguito il codice generato in automatico e non modificato da me.

@implementation ScoreView

#pragma mark -
#pragma mark Memory Management

- (void)dealloc {
[tv_ScoresCellTextValues release];
[tv_ScoresCellDetailTextValues release];
[tv_ScoresSectionTextValues release];
[tv_ScoresFooterText release];
[tv_ScoresACellTextValues release];
[tv_ScoresACellDetailTextValues release];
[tv_ScoresASectionTextValues release];
[tv_ScoresAFooterText release];
[tv_ScoresBCellTextValues release];
[tv_ScoresBCellDetailTextValues release];
[tv_ScoresBSectionTextValues release];
[tv_ScoresBFooterText release];
[super dealloc];
}

#pragma mark -
#pragma mark Initialization

- (id)initWithParentViewController:(ScoreViewController *)parent {
if ((self = [super init])) {
	// Update this to initialize the view with your own frame size
	[self setFrame:CGRectMake(0, 0, 320, 460)];

	// Assign the reference back to the parent view controller
	refParentViewController = parent;

	// Set the view background color
	[self setBackgroundColor:[uIColor colorWithRed:0.247059 green:0.498039 blue:0.498039 alpha:1.000000]];

	// Load subview methods
	[self loadbt_SetScore];
	[self loadtv_Scores];
	[self loadtv_ScoresA];
	[self loadtv_ScoresB];
}
return self;
}

#pragma mark -
#pragma mark Load Subview Methods

- (void)loadbt_SetScore {
UIButton *bt_SetScore = [uIButton buttonWithType:UIButtonTypeRoundedRect];
[bt_SetScore setTitle:@"Set score" forState:UIControlStateNormal];
[bt_SetScore setTitleColor:[uIColor blackColor] forState:UIControlStateNormal];
[bt_SetScore setBackgroundColor:[uIColor clearColor]];
[bt_SetScore addTarget:refParentViewController action:@selector(bt_SetScoreAction) forControlEvents:UIControlEventTouchUpInside];
[bt_SetScore setFrame:CGRectMake(100, 410-44, 97, 31)];
[self addSubview:bt_SetScore];
}

- (void)loadtv_Scores {
UITableView *tv_Scores = [[uITableView alloc] initWithFrame:CGRectMake(0, 44-44, 320, 68) style:UITableViewStylePlain];
[tv_Scores setDataSource:self];
[tv_Scores setDelegate:self];
tv_ScoresCellTextValues = [[NSArray alloc] initWithObjects:@"2345 - 1224", nil];
tv_ScoresCellDetailTextValues = [[NSArray alloc] initWithObjects:@"", @"", @"", nil];
tv_ScoresSectionTextValues = [[NSArray alloc] initWithObjects:@"Test", nil];
tv_ScoresSelectedRow = 0;
tv_ScoresShowHeader = YES;
tv_ScoresFooterText = @"";
[tv_Scores setEditing:NO];
[tv_Scores setBackgroundColor:[uIColor whiteColor]];
[self addSubview:tv_Scores];
}

- (void)loadtv_ScoresA {

UITableView *tv_ScoresA = [[uITableView alloc] initWithFrame:CGRectMake(0, 112-44, 163, 286) style:UITableViewStylePlain];
[tv_ScoresA setDataSource:self];
[tv_ScoresA setDelegate:self];
tv_ScoresACellTextValues = [[NSArray alloc] initWithObjects:@"1800", @"1100", @"500", nil];
tv_ScoresACellDetailTextValues = [[NSArray alloc] initWithObjects:@"", @"", @"", nil];
tv_ScoresASectionTextValues = [[NSArray alloc] initWithObjects:@"Player/Team 1", nil];
tv_ScoresASelectedRow = 0;
tv_ScoresAShowHeader = YES;
tv_ScoresAFooterText = @"";
[tv_ScoresA setEditing:NO];
[tv_ScoresA setBackgroundColor:[uIColor whiteColor]];
[self addSubview:tv_ScoresA];
}

- (void)loadtv_ScoresB {
UITableView *tv_ScoresB = [[uITableView alloc] initWithFrame:CGRectMake(163, 112-44, 157, 286) style:UITableViewStylePlain];
[tv_ScoresB setDataSource:self];
[tv_ScoresB setDelegate:self];
tv_ScoresBCellTextValues = [[NSArray alloc] initWithObjects:@"800", @"300", @"100", nil];
tv_ScoresBCellDetailTextValues = [[NSArray alloc] initWithObjects:@"", @"", @"", nil];
tv_ScoresBSectionTextValues = [[NSArray alloc] initWithObjects:@"Player/Team 2", nil];
tv_ScoresBSelectedRow = 0;
tv_ScoresBShowHeader = YES;
tv_ScoresBFooterText = @"";
[tv_ScoresB setEditing:NO];
[tv_ScoresB setBackgroundColor:[uIColor whiteColor]];
[self addSubview:tv_ScoresB];
}

- (void)loadnb_RetMainPage {
UINavigationBar *nb_RetMainPage = [[uINavigationBar alloc] init];
[nb_RetMainPage setBarStyle:UIBarStyleDefault];
[nb_RetMainPage setTranslucent:NO];
UINavigationItem *navigationItem = [[uINavigationItem alloc] initWithTitle:@"Score"];
[navigationItem setLeftBarButtonItem:[[uIBarButtonItem alloc] initWithTitle:@"Main page" style:UIBarButtonItemStylePlain target:nil action:nil]];
[nb_RetMainPage setItems:[NSArray arrayWithObject:navigationItem]];
[navigationItem release];
[nb_RetMainPage setFrame:CGRectMake(0, 0, 320, 44)];
[self addSubview:nb_RetMainPage];
}

#pragma mark -
#pragma mark TableView Delegates

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {

return [tv_ScoresCellTextValues count];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [tv_ScoresSectionTextValues count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (tv_ScoresShowHeader == TRUE) {
	return [tv_ScoresSectionTextValues objectAtIndex:section];
}
return nil;
}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
if ([tv_ScoresFooterText length] > 0) {
	return tv_ScoresFooterText;
}
return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
	cell = [[[uITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

	// Set the cell text color
	[cell.textLabel setTextColor:[uIColor darkTextColor]];

// Delegates currently only work with one table view, please create a custom
// implementation to handle additional table views
cell.textLabel.text = [tv_ScoresCellTextValues objectAtIndex:indexPath.row];

// Make sure we don't go past end cell detail text values array
if (indexPath.row < [tv_ScoresCellDetailTextValues count]) {
	cell.detailTextLabel.text = [tv_ScoresCellDetailTextValues objectAtIndex:indexPath.row];
}

// Check if this is the selected row
// Note: This goes against Apple UI guidelines, consider removing this or using checkmark accessories
if (indexPath.row == tv_ScoresSelectedRow - 1) {
	[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}

cell.accessoryType = UITableViewCellAccessoryNone;

return cell;
}

// Handle user selecting row event
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
	default:
		break;
}
}

Penso che il problema sia nella parte del codice che gestisce il numero delle righe e delle informazioni della tabella, la parte dopo il tag #pragma mark TableView Delegates

Un ringraziamento per l'aiuto.

L'Uomo in Nero fuggì nel deserto, ed il pistolero lo seguì....

MacBook Pro 15' 2009 - 8 GB RAM / iMac 2011 21,5 - 2,7 GHz - 12 GB RAM / iPod Touch 4th generazione / iPod nano 3th generazione / iPad 1th generazione 32GB

Link al commento
Condividi su altri siti

Risolto!!!

All'interno dei metodi presenti #pragma mark TableView Delegates ho aggiunto il controllo su quale tabella si opera, in questo modo è stato possibile gestire le tre view.

Di seguito il codice del primo metodo, gli altri metodi seguono lo stesso principio

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {

[i]if (table == self.tv_Scores)[/i] {
	return [tv_ScoresCellTextValues count];
}
else {
	[i]if (table == self.tv_ScoresA)[/i] {
		return [tv_ScoresACellTextValues count];
	}
	else {
		return [tv_ScoresBCellTextValues count];
	}
}
}

Le parti in corsivo rappresentano i controlli inseriti. Le tre TableView sono identificate con tv_Scores, tv_ScoresA e tv_ScoresB.

Un saluto a tutti, spero sia utile.

L'Uomo in Nero fuggì nel deserto, ed il pistolero lo seguì....

MacBook Pro 15' 2009 - 8 GB RAM / iMac 2011 21,5 - 2,7 GHz - 12 GB RAM / iPod Touch 4th generazione / iPod nano 3th generazione / iPad 1th generazione 32GB

Link al commento
Condividi su altri siti

Archiviato

Questa discussione è archiviata e chiusa a future risposte.

×
×
  • Crea Nuovo...