When you use UITableView, you often customize the cell for each row
In the iOS control UITableView, the following code modifies some of the code to implement the custom cell.
[CPP]View Plaincopy
- -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
Custom code:
[CPP]View Plaincopy
- static NSString *cellwithidentifier = @"Cell";
- UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellwithidentifier];
- if (cell = = nil) {
- cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellwithidentifier];
- }
- Nsuinteger row = [Indexpath row];
- //Custom cell in image
- Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (20, 24, 24, 24)];
- Imageview.image = [UIImage imagenamed:@"Green.png"];
- [Cell.contentview Addsubview:imageview];
- [ImageView release];
- //Custom text information
- UILabel *city = [[UILabel alloc] Initwithframe:cgrectmake (50, 25, 100, 20)];
- NSString *citystring = [[NSString alloc] initwithformat:@"City:%@", [Self.datalist Objectatindex:row]];
- City.text = citystring;
- [Cell.contentview addsubview:city];
- [Citystring release];
- Cell.textLabel.text = [Self.datalist objectatindex:row];
- Cell.imageView.image = [UIImage imagenamed:@ "Green.png"];
- Cell.detailTextLabel.text = @ "More information";
- Cell.accessorytype = Uitableviewcellselectionstylegray;
iOS Custom UITableViewCell