UITableView proxy Protocol Summary, uitableview proxy Protocol

Source: Internet
Author: User

UITableView proxy Protocol Summary, uitableview proxy Protocol
UITableView proxy Protocol Summary
1./** total number of groups */-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView
{
Return self. personGroups. count;
}

2./** how many rows each group has */
-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section
{
SUNPersonGroupInfo * personGroupInfo = self. personGroups [section];
Return personGroupInfo. persons. count;
}

3./** display the content of each row */-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
// Because of the cell reuse mechanism, the system will first find the cell with the same idle name from the automatic release pool. If there is one, the system will reuse the cell and create a new one if there is no idle cell,
Static NSString * cellName = @ "cell ";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellName];
If (cell = nil ){
Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: cellName];
}
// Because of the cell reuse mechanism, you need to clear all cell settings. Otherwise, errors may occur during the subsequent reuse.
Cell. textLabel. text = nil;
Cell. detailTextLabel. text = nil;
Cell. accessoryType = UITableViewCellAccessoryNone;
// Set the split line
Cell. selectionStyle = UITableViewCellSelectionStyleNone;
Cell. textLabel. font = nil;

If (indexPath. section = 0 ){
// Set the subject and subtitle of the cell (the style of the cell is different, the effect is different, and some do not have the subtitle)
Cell. textLabel. text = @ "Main title ";
Cell. detailTextLabel. text = @ "subtitle ";
// Set the style of the button appended to the right of the cell. Only the following style can be clicked. other styles cannot be clicked.
Cell. accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
Cell. selectionStyle = UITableViewCellSelectionStyleBlue;
Cell. textLabel. font = [UIFont systemFontOfSize: 20];
Cell. imageView. image = [UIImage imageNamed: @ "001_1"];
// Affiliated view on the right of the cell
UIButton * btn = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[Btn addTarget: self action: @ selector (btnClick) forControlEvents: UIControlEventTouchUpInside];
[Btn setTitle: @ "do you have" forState: UIControlStateNormal];
Btn. frame = CGRectMake (0, 0, 50, 30 );
Cell. accessoryView = btn;
// Make the following settings if the selected color does not change.
// Cell. selectionStyle = UITableViewCellSelectionStyleNone;
// No split line is required
// TableView. separatorStyle = UITableViewCellSeparatorStyleNone;
} Else {
Cell. textLabel. text = @ "second cell ";
}
Return cell;
}
Note: The cell of the specified row is returned. This is a key part. In this part, you can customize various personalized cell elements. Here is just the simplest and most basic cell type. There is a main title cell. textLabel also has a subtitle cell. detailTextLabel, and an image named cell at the beginning. imageView. you can also set the icon on the right through cell. accessoryType can be set to a full blue arrow to the right, a thin arrow to the right, or a check mark.

4. // This method returns the height of the specified row.
-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath;

5. // This method returns the height of the header view of the specified section.
-(CGFloat) tableView :( UITableView *) tableView heightForHeaderInSection :( NSInteger) section;
6. // This method returns the footer view height of the specified section.
-(CGFloat) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger) section;
7./** return title text */-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section
{
SUNPersonGroupInfo * personGroup = self. personGroups [section];
Return personGroup. title;
}

8./** right index */
-(NSArray *) sectionIndexTitlesForTableView :( UITableView *) tableView
{
Return [self. personGroups valueForKey: @ "title"];
}

// Start editing. Once editing = YES, the deletion mode is enabled by default. If self. tableView. editing = NO;
9. // edit mode-(UITableViewCellEditingStyle) tableView :( UITableView *) tableView editingStyleForRowAtIndexPath :( NSIndexPath *) indexPath
{
Return UITableViewCellEditingStyleInsert;
} UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete, delete
Add UITableViewCellEditingStyleInsert
10. // display the Drag Control-(BOOL) tableView :( UITableView *) tableView canMoveRowAtIndexPath :( NSIndexPath *) indexPath
{
Return YES;
} 11. // call this operation when the cell of a row is selected. But first, you must set a tableview attribute to select.
-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath
{
NSLog (@ "row % d in section % d is clicked", indexPath. section, indexPath. row );
}
Note: If you do not want to respond to the select statement, you can use the following code to set attributes:
TableView. allowsSelection = NO;

12. // set the split line between each row in tableview. If you do not need to split the line, set the attribute to UITableViewCellSeparatorStyleNone.
Self. tableView. separatorStyle = UITableViewCellSeparatorStyleSingleLine;

13. // how to set the background color of tableview cell
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
// Set the background color
Cell. contentView. backgroundColor = [UIColor colorWithRed: 0.957 green: 0.957 blue: 0.957 alpha: 1];
}

// Response to this function. Click the arrow on the right of the cell (if any)
-(Void) tableView :( UITableView *) tableView accessoryButtonTappedForRowWithIndexPath :( NSIndexPath *) indexPath

// To edit a tableview, you must first enter the edit mode. to exit the edit mode, you must set it to NO.
[TableView setEditing: YES animated: YES];

// Return the edits to be executed by the current cell. The following code returns the deletion mode.
-(UITableViewCellEditingStyle) tableView :( UITableView *) tableView editingStyleForRowAtIndexPath :( NSIndexPath *) indexPath


// The Notification tells the user which cell has been edited. corresponding to the code above, we will delete the cell in this function.
-(Void) tableView :( UITableView *) aTableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath

2. // slide to delete
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath
{
If (editingStyle = UITableViewCellEditingStyleInsert ){
}
}

3. // The button displayed on the left is delegate by default;-(NSString *) tableView :( UITableView *) tableView titleForDeleteConfirmationButtonForRowAtIndexPath :( NSIndexPath *) indexPath
{
Return @ "delete ";
}
Note: by default, there is a UITableView, AND self. tableview = self. view uses the following two statements for tracking and verification.
NSLog (@ "% p", self. view, self. tableView );
NSLog (@ "% @", self. view. class );

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.