Uitableview, which is used to assign values to cells by encapsulating classes.

Source: Internet
Author: User

# Import "rootviewcontroller. H"

# Import "person. H"

 

@ Interface rootviewcontroller () <uitableviewdatasource>

@ Property (nonatomic, retain) nsmutablearray * array;

 

@ End

 

@ Implementation rootviewcontroller

-(Void) dealloc

{

[_ Array release];

[Super dealloc];

}

 

-(Void) viewdidload {

[Super viewdidload];

Self. View. backgroundcolor = [uicolor cyancolor];

// You Need A View Controller to create a navigation controller. Therefore, you must first create a View Controller so that the navigation controller will manage this attempt controller.

// Make the navigation controller the Root View Controller of appdelegate

// Move and edit uitableview

Uitableview * tableview = [[uitableview alloc] initwithframe: Self. View. bounds style :( uitableviewstyleplain)];

Tableview. rowheight = 100; // The Row Height. The default value is 44.

Tableview. backgroundcolor = [uicolor yellowcolor];

Tableview. datasource = self; // specifies a proxy for the proxy to provide data

[Self. View addsubview: tableview];

[Tableview release];

[Self creatdata]; // transfers some code to a method.

}

-(Void) creatdata {

Person * P1 = [person personwithname: @ "" number: @ "123"];

Person * P2 = [person personwithname: @ "raccoon" number: @ "456"];

Person * P3 = [person personwithname: @ "pop-up" number: @ "789"];

Person * P4 = [person personwithname: @ "Skip" number: @ "423"];

Self. array = [nsmutablearray arraywithobjects: P1, P2, P3, P4, nil];

}

 

 

-(Void) didreceivememorywarning {

[Super didreceivememorywarning]; // receives a memory warning, passively triggered

}

 

 

# Pragma mark-uitableviewdatasource

 

-(Nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {// set the number of rows

Return self. array. count;

}

 

-(Uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {

// Create a cell

// 1. Set the identifier and find the cell

Static nsstring * STR = @ "cell ";

Uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier: Str]; // find the cell in the reuse pool

If (cell = nil ){

Cell = [[[uitableviewcell alloc] initwithstyle :( uitableviewcellstylevalue1) reuseidentifier: Str] autorelease]; // direct release is not suitable, so autorelease is used

}

// Assign values to cells

// Cell. textlabel. Text = @ "name ";

// Cell. detailtextlabel. Text = @ "phone ";

Person * person = [self. array objectatindex: indexpath. Row];

Cell. textlabel. Text = person. Name;

Cell. detailtextlabel. Text = person. number;

Return cell;

}

 

 

 

@ End

 

Uitableview, which is used to assign values to cells by encapsulating classes.

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.