iOS Custom UITableViewCell

Source: Internet
Author: User

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
    1. -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

Custom code:

[CPP]View Plaincopy
  1. static NSString *cellwithidentifier = @"Cell";
  2. UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellwithidentifier];
  3. if (cell = = nil) {
  4. cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellwithidentifier];
  5. }
  6. Nsuinteger row = [Indexpath row];
  7. //Custom cell in image
  8. Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (20, 24, 24, 24)];
  9. Imageview.image = [UIImage imagenamed:@"Green.png"];
  10. [Cell.contentview Addsubview:imageview];
  11. [ImageView release];
  12. //Custom text information
  13. UILabel *city = [[UILabel alloc] Initwithframe:cgrectmake (50, 25, 100, 20)];
  14. NSString *citystring = [[NSString alloc] initwithformat:@"City:%@", [Self.datalist Objectatindex:row]];
  15. City.text = citystring;
  16. [Cell.contentview addsubview:city];
  17. [Citystring release];
  18. Cell.textLabel.text = [Self.datalist objectatindex:row];
  19. Cell.imageView.image = [UIImage imagenamed:@ "Green.png"];
  20. Cell.detailTextLabel.text = @ "More information";
  21. Cell.accessorytype = Uitableviewcellselectionstylegray;


iOS Custom UITableViewCell

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.