Custom cell (IOS)
There are three methods to customize Cells
-Code Implementation
-Xib
-Storyboard (recommended)
In the story board, the operation method is
1. Set Prototype Cells to 1 in TableView. The default value is 1;
2. Create a custom cell class;
3. Set the Class of Table View Cell as the custom Class;
Custom class: (not difficult)
#import "CustomCell.h"@implementation CustomCell- (void)awakeFromNib { // Initialization code}- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state}@end
Required data source protocols:
# Pragma mark -- UITableViewDataSource protocol method-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return [self. listTeams count];}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {// defines the reusable Cell object static NSString * cellIdentifier = @ "Cell "; customCell * cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier]; NSUInteger row = [indexPath row]; NSDictionary * rowDict = [self. listTeams objectAtIndex: row]; cell. name. text = [rowDict objectForKey: @ "name"]; NSString * imagePath = [rowDict objectForKey: @ "image"]; imagePath = [imagePath stringByAppendingString :@". png "]; cell. image. image = [UIImage imageNamed: imagePath]; cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell ;}