Xcode 4.3.2 storyboard: Drawing UITableView to understand storyboard usage and tableview

Source: Internet
Author: User

1. Xcode creates a single view application

2. Delete the default viewcontroller In the storyboard.

3. Drag table view controller and a table view cell.
[Select the table view cell you just dragged in
3.1 modify the Identifier in the Table View Cell attribute to myCell. After that, this flag needs to be used for Program Control in myTableViewController. m to reference this Cell and set the data in it.
3.2 currently, the Content parameter of table view is still the default Dynamic Prototypes. If static cells is set, an error will occur. Please leave a message to inform us if you know it. Thank you, I am also playing iOS development __
You can set the Style parameter of table view to Grouped.
]

4. Menu: editor-> embed in-> navigation controller

* 5 this step can also not be performed: drag the tab bar controller to the storyboard
* 5.1 Delete two view controllers under tab bar controller.
* 5.2 press and hold the cntrol key to pull the line from the tab bar controller to the navigation controller. In the displayed dialog box, select "Relationship-> viewControllers"
* 5.3 select the tab bar controller and set attributes: select is Initial View Controller to make the tab bar controller the initialized view controller.

6. Create a File, Cocoa Touch-> Objective-C class.
Set Class: myTableViewController
Set Subclass of: UITableViewController
// MyTableViewController inherits UITableViewController

7. Edit myTableViewController. h.
Define the class: myTableViewController as follows:

@ Interface myTableViewController: UITableViewController
{
NSMutableArray * lists; // added to define the content displayed in the table
}

@ Property (nonatomic, strong) NSMutableArray * lists; // Add


8. Modify myTableViewController. m.
@ Implementation myTableViewController

@ Synthesize lists; // added

-(Void) viewDidLoad
{
[Super viewDidLoad];
// Add the following: Define lists data
Self. title = @ "Lists ";
Lists = [[NSMutableArray alloc] initWithCapacity: 20];
[Lists addObject: @ "test1"];
[Lists addObject: @ "test2"];
[Lists addObject: @ "test3"];
[Lists addObject: @ "test4"];
[Lists addObject: @ "test5"];

}

// The following three functions are generated after the myTableViewControll file is created.
-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView
{
// Delete this row # warning row
// Return the number of sections.
Return 1;
}

-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{
// Delete this row # warning Incomplete method implementation.
// Return the number of rows in the section.
Return [self. lists count];
}


// The following function is used to display data in the table.
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath
{
Static NSString * CellIdentifier = @ "myCell"; // modify this flag. This flag is set in storyboard and cannot be written incorrectly. Otherwise, the lists data is not displayed in the table.
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

// Configure the cell...
// Add the following cell configuration to display list data in cells marked as "myCell"
NSInteger row = [indexPath row];
Cell. textLabel. text = [self. lists objectAtIndex: row];
Return cell;
}

Another method is to mount a common view controller container behind the navigation controller, and drag table view and table view cell into the container.

This method: Create the controller corresponding to the view controller container. h and. m file ,. the class in the H file must inherit the datasource and delegate of UITableViewController. in the m file, you must implement the following three methods in method 1.

NumberOfSectionsInTableView ()

NumberOfRowsInSection ()

CellForRowAtIndexPath ()

 


From gaoxuefeng's column

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.