У меня есть UITableView, правильно заполняющий данные. Табличное представление находится внутри другого представления. Когда это родительское представление загружено, как я могу установить галочку для первой строки в табличном представлении?

@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];
}

Изменить: я хочу, чтобы при создании представления проверялась только первая строка. Только одна строка во второй группе должна быть выбрана (установлена ​​галочка). Это моя полная ячейкаForRowAtIndexPath, вы можете определить проблемы?

- (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;
}
0
john 22 Июл 2009 в 19:15

2 ответа

Вам нужно будет реализовать это в методе cellForRowAtIndexPath контроллеров табличного представления.

if (indexPath.row == 0)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
4
Brandon Schlenker 22 Июл 2009 в 20:23

Попробуйте этот ответ:

if (cell.accessoryType == UITableViewCellAccessoryNone) {
   cell.accessoryType = UITableViewCellAccessoryCheckmark;  
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
   cell.accessoryType = UITableViewCellAccessoryNone;
}
0
sth 19 Сен 2009 в 18:47