In IOS development, tableView displays the list content data (storyboard) and iostableview

Source: Internet
Author: User

In IOS development, tableView displays the list content data (storyboard) and iostableview

This is the first time I wrote such a blog, and I am also a newbie-level self-taught IOS. If you have any incorrect ideas, please correct them. Thank you...

 

First, let's write a list of things that everyone will use from school. Maybe you don't think this is a problem. It's because you are smart and it's bothering me when I first went to school. I 'd like to write it specially;

 

Step 1: Create a project IOS -- "single view application

-- "Product Name: tableViewDemo

Language: Objective-C

Devices: iPhone,

Click NEXT, select your folder, and Create

--> Click to open Main. storyboard (we will use the View Controller that comes with the project generation)

Find the UITableView control in the control bar and drag it to the attempt controller (you can overwrite all or overwrite some areas)

 

Step 2: Set dataSource and delegate for tableview

-- Click the first yellow sign at the top of the page, and then click the last button at the top of the page;

 

-- In the Referencing Outlets column, drag a line from the hollow circle to the UITableView control we just covered; dataSource and delegate are displayed; select delegate;

-- Repeat the Drag and Drop Process and select dataSource;

 

Step 3: Display Codes

-- Open ViewController. h file

 #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>@end

 

 

-- Open the ViewController. m file and implement the proxy method of tableview

(1) defines the global variable arrayData, which is used to hold the content text to be displayed on the list.

(2) initialize the array variables in ViewDidLoad;

(3) Implement proxy Methods

# Import "ViewController. h "@ interface ViewController () @ property (nonatomic, strong) NSArray * arrayData; @ end @ implementation ViewController @ synthesize arrayData;-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. arrayData = [NSArray arrayWithObjects: @ "", @ "", nil];} # pragma mark -- delegate method-(NSInteger) number OfSectionsInTableView :( UITableView *) tableView {return 1;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return arrayData. count;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * indentifier = @ "cell"; UITableViewCell * cell = [tableView progress: indentifier]; I F (! Cell) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: indentifier];} cell. textLabel. text = [arrayData objectAtIndex: indexPath. row]; return cell;}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} @ end

 

Click Run.

 

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.