0
在很多iPhone应用程序中,我看到一个UITableViewController被用作复选框列表。 (例如,我的意思是,在设置下的自动锁定的例子)使用UITableViewController作为复选框列表时选择默认项目
虽然试图自己实现这一点,但我不得不跳过大量的箍环,以便在默认情况下以编程方式选择项目(即。 ,列表所代表的当前值)。最好的我已经能够拿出是在我的视图控制器类中重写viewDidAppear方法:
- (void)viewDidAppear:(BOOL)animated {
NSInteger row = 0;
// loop through my list of items to determine the row matching the current setting
for (NSString *item in statusItems) {
if ([item isEqualToString:currentStatus]) {
break;
}
++row;
}
// fetch the array of visible cells, get cell matching my row and set the
// accessory type
NSArray *arr = [self.tableView visibleCells];
NSIndexPath *ip = [self.tableView indexPathForCell:[arr objectAtIndex:row]];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:ip];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.lastIndexPath = ip;
[super viewDidAppear:animated];
}
这是最好的/只/最容易得到一个特定的细胞和indexPath如果引用的方式我想默认标记一行?
看,我觉得我是愚蠢的代码。今天缓慢的大脑:P – Dana 2009-08-12 19:14:15