There are 4 types of UITableViewCell default units:
1.UITableViewCellStyleDefault
2.UITableViewCellStyleSubtitle
3.uitableviewcellstylevalue1
4.uitableviewcellstylevalue2
To begin with, the default cell uses 3 different elements.
- Image: If the specified style contains an image, the image is displayed to the left of the text of the cell.
- text Label: The main text of the cell.
- Detail Text Label: A unit of auxiliary text, usually used as an explanatory note or label.
How do I use these four kinds of cells? As below, modify the Red section to use one of the cell styles
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath { StaticNSString *simpletableidentifier =@"Simpletableidentifier";UITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:simpletableidentifier]; if(Cell = =Nil) { //If there are no reusable cell objects, use the identifier to recreate a cell object.Cell =[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier: Simpletableidentifier]; } //The default cell contains the picture cell.imageView.image = [UIImage imagenamed:@ "star1"]; //picture in normal state cell.imageView.highlightedImage = [UIImage imagenamed:@ "star2"];//picture is selected, highlight State//The default cell contains the text Cell.textLabel.text = Self.datas[indexpath.row]; //The default cell contains a detailed text label Cell.detailTextLabel.text = [NSString stringWithFormat:@ "detail%li", indexpath.row+ 1 ]; returncell;}
Run
You can see that the picture is set to a highlighted state, and a different picture is displayed when selected. But why is the headline not in detail?
This is because the style used is uitableviewcellstyledefault, and this style does not show detailed headings. The following are the other 3 different styles of operation:
2.UITableViewCellStyleSubtitle
3.uitableviewcellstylevalue1
4.uitableviewcellstylevalue2, do not display pictures, all text right-aligned, all detailed text left-aligned.
iOS Learning--uitableview table View cell styles