Each group in a group table is a partition. In an index table, each index is a partition.
Implement a simple table:
First, drag a tableview in the xib File and connect its dataSource and delegate to the File's owner.
@ Interface Hello_WorldViewController: UIViewController <UITableViewDelegate, UITableViewDataSource> {
}
The purpose of the above Code is to let the class follow two protocols. The class requires these two protocols to act as the delegate and data source for the performance diagram. The data source provides all the data required to draw the table, used to configure the appearance of a table View
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{
Return self. listData. count;
}
The preceding method indicates that this section has several table items. The default section value is 1.
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath
{
Static NSString * simpleTableIdentifier = @ "simpleIdentifier ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier];
If (cell = nil)
{
Cell = [[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: simpleTableIdentifier];
}
NSUInteger row = [indexPath row];
Cell. text = [self. listData objectAtIndex: row];
Return cell;
}
The above function is used to plot the cell. The first parameter represents the initiator used to draw the cell, and the second parameter is indexPath. Through this parameter, we can get section and row,
The table view can only display a limited number of rows on the iphone at a time, but it indicates that the graph data volume can be large. If we allocate a cell for each row of data, the overhead will be very large.
At the same time, we found that some cells are currently displayed, and some are not. When a cell gets out of the screen, other cells will be rolled from the other side to the screen, if you roll to the cell on the screen and use the cell out of the screen again, the system will not waste space and time to create or delete a new cell. We use simpleTalbeIdentifier to identify each cell and call [tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier] to check whether the cell with this identifier has appeared in the reusable queue before. If yes, use it directly, if not, it is nil, cell = [[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: Create a cell.
-(Void) tableView :( UITableView *) tableView didDeselectRowAtIndexPath :( NSIndexPath *) indexPath
{
NSUInteger section = [indexPath row];
NSLog (@ "setion is % d", section );
NSString * rowValue = [self. listData objectAtIndex: section];
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "message: rowValue delegate: nil cancelButtonTitle: @" cancel "otherButtonTitles: nil];
[AlertView show];
}
The preceding method indicates that it is called when a cell is clicked.
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath
{
Return 100;
}
The above method returns the height of each cell based on indexPath.