Detailed in IOS custom cell, custom Uitableviewcell_ios

Source: Internet
Author: User

To customize a cell by inheriting UITableViewCell

1, create an empty project, named:

2. Create a Uitableviewcontroller and create xib at the same time:

3. Set the root controller of windows in APPDELEGATE.M for the tableviewcontroller you just created:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions 
{ 
  Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; 
  Tableviewcontroller *tableviewcontroller = [[[Tableviewcontroller alloc] init] autorelease]; Automatic release 
  //Set root controller 
  self.window.rootViewController = Tableviewcontroller; 
  [Self.window makekeyandvisible]; 
  return YES; 

4. Create custom UITableViewCell:

5. Create a custom cell xib drag and drop the controls you want
Select User Interface.

Create an empty xib.

Drag into the cell control.

Complete the custom cell control.

Sets the identfier of the cell control.

Binds the cell class and associates the control's exports with the TableViewCell.h file.

6, to the Tableviewcontroller class code, in the delegate method to set the custom cell:

#import "TableViewController.h" #import "TableViewCell.h" @interface Tableviewcontroller () {Nsmutablearray *table Data; Tabular data} @end @implementation Tableviewcontroller-(ID) Initwithstyle: (Uitableviewstyle) style {self = [supe 
  R Initwithstyle:style]; 
if (self) {//Custom initialization} return self; 
  }-(void) viewdidload {[Super viewdidload]; 
  Initialize table Data Tabledata = [[Nsmutablearray alloc] init]; 
  for (int i = 0; i< i++) {[Tabledata addobject:[nsstring stringwithformat:@ ' mycelldemon%i ', I]]; 
  
//Set the height of row to the height of the custom cell self.tableView.rowHeight = 90; 
 }-(void) didreceivememorywarning {[Super didreceivememorywarning]; } #pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {#warni 
   Ng potentially incomplete method implementation. 
return 1; }-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {#warning incomplete method implementation. 
return [Tabledata Count]; }-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath {//Designated cell 
  Identifier is a custom cell static nsstring *cellidentifier = @ "Tableviewcell"; 
  Custom cell class Tableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {//load the custom cell cell by the name of Xib = [[[NSBundle Mainbundle] loadnibnamed:@ "Tableviewcell" owner:self 
  Options:nil] Lastobject]; 
  ///Add test data Cell.titleLabel.text = [Tabledata ObjectAtIndex:indexPath.row]; 
  Cell.content.text = @ "This is some test data"; 
   Test picture cell.iamge.image = [UIImage imagenamed:@ "testimage.jpg"]; 
return cell;  #pragma mark-table View delegate-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath 
 *) Indexpath {} @end

Final effect:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.