如何在UITableview的每一行中存储布尔值。我需要检索存储在单元格中的布尔值,当该特定单元格被选中时。在UITableviewcell中存储布尔值
0
A
回答
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可以访问在其上用户点击的细胞。 }
相关问题
- 1. 存储布尔值
- 2. 在Android中存储多个布尔值
- 3. 在SQL中存储布尔值?
- 4. 如何将布尔值存储到NSArray?
- 5. 布尔值没有正确存储?
- 6. 存储布尔值:捆绑还是单独存储?
- 7. 更改存储在数组中的对象的布尔值
- 8. 如何更新在GAE数据存储中的布尔值?
- 9. 在表单处理的隐藏字段中存储布尔值
- 10. 我应该如何在mongodb中存储布尔值?
- 11. 什么是在MySQL中存储布尔值的数据类型?
- 12. 取消存储在NSNumber中的布尔值
- 13. 如何将一组布尔值存储在MySql数据库中?
- 14. 有多少个字节用于在Java中存储布尔值?
- 15. NSPredicate - 基于布尔值存储值筛选值
- 16. 布尔索引的列值存储为一个变量在python
- 17. 在服务器上存储一个布尔值
- 18. SharedPreferences不保存布尔值
- 19. 调用存储过程,传递NULL值,处理布尔值
- 20. vb6集合存在和布尔值集
- 21. Container中的寄存器布尔值
- 22. 布尔值与tinyint(1)在MySQL中的布尔值
- 23. 在德尔福存储一组数值
- 24. 是否有可能存储在Java中的字符串中的布尔值
- 25. 在UITableViewCell中存储唯一ID
- 26. Bash比较存储的“布尔”值与什么?
- 27. 从T-SQL存储过程返回布尔值
- 28. 写整数值不布尔到存储器字100
- 29. 为什么Stata将布尔值存储为float?
- 30. 检查布尔返回值pdo的mysql存储函数