我正在使用两个 NSMutable 数组来存储多个复选标记.. repeatDaysToStore和data1。这是 viewDidLoad 方法中的代码...
for (int i=1; i<=[repeatDaysToStore count]; i++)
{
BOOL isTheObjectThere = [repeatArray containsObject:[repeatDaysToStore objectAtIndex:(i-1)]];
if (isTheObjectThere)
{
NSString *into=[repeatArray objectAtIndex:[repeatArray indexOfObject:[repeatDaysToStore objectAtIndex:(i-1)]]];
[data1 addObject:into];
NSLog(@"check did load");
}
}
在此之后我使用 data1 数组来检查单元格......
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[repeatArray objectAtIndex:indexPath.row];
tableView.allowsMultipleSelection=YES;
for (int j=1; j<=[data1 count]; j++) {
NSLog(@"%d",[[data1 objectAtIndex:(j-1)]intValue]);
NSLog(@"%d",indexPath.row);
if([data1 indexOfObject:[data1 objectAtIndex:(j-1)]]==indexPath.row)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
为了处理行选择,我在 didSelectRowAtIndexPath { NSString *myobj=[repeatArray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
[repeatDaysToStore removeObject:myobj];
[data1 removeObject:myobj];
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[repeatDaysToStore addObject:myobj];
[data1 addObject:myobj];
}
[tableView reloadData];
}
但它不起作用。有人请告诉我出了什么问题?