Iphone 在UITableviewcell中存储布尔值

Iphone 在UITableviewcell中存储布尔值,iphone,ios,uitableview,boolean,Iphone,Ios,Uitableview,Boolean,如何在UITableview的每一行中存储布尔值。我需要检索存储在单元格中的布尔值,当选择该特定单元格时。您可能还有其他存储,其中保存了表格单元格标题或副标题之类的内容。将布尔值存储在那里。使用此选项可以将bool转换为可以放入数组或字典中的内容 [NSNumber numberWithBool:YES] 例如,如果使用字符串的NSArray来存储标题,则使用字典数组。每个字典都有一个“title”和(例如)“isActive”布尔值(存储为NSNumber)。您可能还有一些其他存储,在这些存

如何在UITableview的每一行中存储布尔值。我需要检索存储在单元格中的布尔值,当选择该特定单元格时。

您可能还有其他存储,其中保存了表格单元格标题或副标题之类的内容。将布尔值存储在那里。使用此选项可以将bool转换为可以放入数组或字典中的内容

[NSNumber numberWithBool:YES]

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

您可能还有一些其他存储,在这些存储中保存诸如表格单元格标题或副标题之类的内容。将布尔值存储在那里。使用此选项可以将bool转换为可以放入数组或字典中的内容

[NSNumber numberWithBool:YES]

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

NSMutableArray*tableData

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

NSMutableArray*tableData

[NSNumber numberWithBool:YES]
每个表单元格都与tableData中的NSMutableDictionary存储关联,
您可以将NSNumber(存储布尔)设置为字典。

有很多方法:
[NSNumber numberWithBool:YES]
1.您可以使用UITableViewCell.tag属性
2.您可以创建从UITableViewCell继承的自己的单元格类,并为您的布尔值添加普通属性
3.您可以使用与tableview关联的数组,当您选择单元格时,只需使用indexPath在数组中查找关联的值

等等。

有很多方法:
1.您可以使用UITableViewCell.tag属性
2.您可以创建从UITableViewCell继承的自己的单元格类,并为您的布尔值添加普通属性
3.您可以使用与tableview关联的数组,当您选择单元格时,只需使用indexPath在数组中查找关联的值

等等。

您需要实现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;
}
  • (void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{ //通过使用indexpath.row,您可以访问用户单击的单元格。 }

您需要实现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;
}
  • (void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{ //通过使用indexpath.row,您可以访问用户单击的单元格。 }

我建议在
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.
}

我建议在
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.
}