J'ai un UITableView correctement peupler avec des données. La vue de la table est dans une autre vue. Lorsque cette vue parent est chargée, comment puis-je définir la première ligne dans la vue de tableau pour avoir une coche?iPhone UITableView, comment définir la ligne par défaut cochée onViewLoad?
@implementation PrefViewController
@synthesize label, button, listData, lastIndexPath;
-(void) viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"European",@"Spanish", nil];
self.listData = array;
// SET TABLEVIEW ROW 0 to CHECKED
[array release];
[super viewDidLoad];
}
Edit: Je veux que la première ligne à être vérifier lorsque la vue est créée. Une seule ligne du deuxième groupe devrait pouvoir être sélectionnée (cochée). C'est mon complet cellForRowAtIndexPath, pouvez-vous repérer les problèmes?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CheckMarkCellIdentifier];
NSUInteger row = [indexPath row];
NSUInteger oldRow = [lastIndexPath row];
if(indexPath.section == 1)
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CheckMarkCellIdentifier] autorelease];
if (indexPath.row == 0)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
cell.text = [listData objectAtIndex:row];
cell.accessoryType = (row == oldRow && lastIndexPath != nil) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
}
else
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CheckMarkCellIdentifier] autorelease];
}
cell.text = [aboutData objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}