2012-02-20 61 views

回答

1

我建议在UITableViewCell中使用标签属性。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;    
// returns nil if cell is not visible or index path is out of range 
{ 

    static NSString *identifier = @"MyIndetifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    //make sure tu put here, or before return cell. 
    cell.tag = 0; //0 =NO, 1=YES; 

    return cell; 
} 

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    BOOL boolean = cell.tag; // return 0 or 1. based on what boolean you set on this particular row. 
} 
0

您可能还有其他一些存储空间,您可以在其中存储表格单元格标题或副标题等内容。在那里存储布尔值。使用它来将bool转换为可以放入数组或字典中的东西。

[NSNumber numberWithBool:YES] 

例如,如果你使用的字符串NSArray存储的标题,而不是使用字典的数组。每个字典都有一个“标题”和(例如)“isActive”布尔值(存储为NSNumber)。

0

NSMutableArray * tableData;

每个表格单元格都与tableData中的一个NSMutableDictionary存储相关联,您可以将一个NSNumber(存储布尔)设置为Dictionary。

2

有这么多的方法:
1.您可以使用UITableViewCell.tag财产
2.您可以创建自己的电池类从继承的UITableViewCell并添加有正常的财产为您bool值
3.您可以使用与您的tableview关联数组,当你选择单元格,只需使用indexPath阵列中找到相关的价值

0

你需要实现的UITableView

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;    
// returns nil if cell is not visible or index path is out of range 
{ 
//create cell here 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    return cell; 
} 
的方法
  • (无效)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath { //使用indexpath.row可以访问在其上用户点击的细胞。 }