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