У меня есть 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;
}
2 ответа
Вам нужно будет реализовать это в методе cellForRowAtIndexPath контроллеров табличного представления.
if (indexPath.row == 0)
cell.accessoryType = UITableViewCellAccessoryCheckmark;
Попробуйте этот ответ:
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
Похожие вопросы
Новые вопросы
iphone
НЕ ИСПОЛЬЗУЙТЕ этот тег, если вы не обращаетесь конкретно к iPhone и / или iPod touch от Apple. Для вопросов, не зависящих от оборудования, используйте тег [ios]. Больше тегов, которые нужно рассмотреть, это [xcode] (но только если вопрос касается самой IDE), [swift], [target-c] или [cocoa-touch] (но не [cocoa]). Пожалуйста, воздержитесь от вопросов, касающихся iTunes App Store или iTunes Connect. Если вы используете C #, пометьте [mono].