2013-05-12 57 views
0

我選擇編程方式使用細胞:無法選擇或訪問的UITableView細胞即出滾動界限(不可見的細胞)的

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:3 inSection:1]; 
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 

UITableViewCell *anotherCell = [self.tableView cellForRowAtIndexPath:indexPath]; 
[anotherCell setSelected:YES]; 
anotherCell.accessoryType = UITableViewCellAccessoryCheckmark; 

這個偉大的工程在UITableView中的所有其他細胞,但對於那些超越視圖邊界的夫婦,當我向下滾動時,我看到單元格上沒有複選標記。

如何將複選標記/選中單元格通過滾動條?

+0

如果不使用這個,你可以保存在一個數組左右,在'的cellForRowAtIndexPath這個選擇indexPath的:'用這個信息來顯示覆選標記。將dataSource綁定到視圖然後重新加載視圖總是更容易。 – Anupdas 2013-05-12 21:46:11

+0

請記住,不可見的單元通常不存在,並根據需要創建。因此你不能(也不應該)使用你的視圖來存儲數據。這就是你的模型的用途。將複選標記的狀態保存在模型或本地屬性中,並將其設置爲cellForRowAtIndexPath。 – lnafziger 2013-05-12 22:03:10

+0

thx!即時通訊確實沒有存儲在單元格中的數據,但我需要保持表的狀態,當它再次加載。當表加載時,我應該在哪裏按程序選擇單元格? – stackOverFlew 2013-05-12 22:34:58

回答

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"genericCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
    cell.textLabel.font = [UIFont systemFontOfSize:22.0]; 


    //set selected based on indexPath.row and indexPath.section 
    [cell setSelected:YES]; 


    //or 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 



}