UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellStr];
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellStr];
}
You can click the record method to record the selected record:
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {// table Click Event
UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath];
NSString * str = cell. textLabel. text;
NSDictionary * dict = [self getOneDictByName: str];
If ([self isExistsByName: str theArray: selectedData]) {
[Self removeOneFromArrayByName: str theArray: selectedData];
} Else {
[SelectedData addObject: dict];
}
[TableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
}
SelectedData in the Code is an NSMutableArray.
Then, the cell accessoryType value is limited in the cellForRowAtIndexPath method.
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
Static NSString * cellStr = @ "cell ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellStr];
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellStr];
}
NSArray * keys = [tempResult allKeys];
NSArray * dicts = [tempResult valueForKey: [keys objectAtIndex: indexPath. section];
NSDictionary * temp = [dicts objectAtIndex: indexPath. row];
Cell. textLabel. text = [temp valueForKey: @ "name"];
If ([selectedData containsObject: temp]) {
Cell. accessoryType = UITableViewCellAccessoryCheckmark;
} Else {
Cell. accessoryType = UITableViewCellAccessoryNone;
}
Return cell;
}
The above if else should be complete.
In fact, the idea is MVC. The view is only used for display. What is displayed depends on the model;