Custom cell (IOS)

Source: Internet
Author: User

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 ;}


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.