Ios: chaotic UITableView UITableViewCellAccessoryCheckmark

Source: Internet
Author: User

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;

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.