IOS Study Notes 2-simple operations on tableView

Source: Internet
Author: User

1. Delete:
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath
{
If (editingStyle = UITableViewCellEditingStyleDelete)
{
NSLog (@"....");
NSUInteger row = indexPath. row;
[Self. editArray removeObjectAtIndex: row];
[TableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation :( UITableViewRowAnimationTop)];
}

// Collect data updates
// [Self replaceCurrentViewData: self. editArray];

}

Implement the above functions

2; Mobile:


-(Void) tableView :( UITableView *) tableView moveRowAtIndexPath :( NSIndexPath *) sourceIndexPath toIndexPath :( NSIndexPath *) destinationIndexPath
{
If (sourceIndexPath! = DestinationIndexPath)
{
Id object = [self. editArray objectAtIndex: sourceIndexPath. row];
[Object retain];
[Self. editArray removeObjectAtIndex: sourceIndexPath. row];
If (destinationIndexPath. row> [self. editArray count])
{
[Self. editArray addObject: object];
}
Else {
[Self. editArray insertObject: object atIndex: destinationIndexPath. row];
}
[Object release];
}
// [Self replaceCurrentViewData: self. editArray];
}

3: insert


This is similar to deleting a row. To achieve this, click the plus sign (+.

3.1 first modify UITableViewCellEditingStyleDelete in the editingStyleForRowAtIndexPath method to UITableViewCellEditingStyleInsert
-(Void) tableView :( UITableView *) tableView commitEditingStyle :( UITableViewCellEditingStyle) editingStyle forRowAtIndexPath :( NSIndexPath *) indexPath
{
If (editingStyle = UITableViewCellEditingStyleDelete)
{
NSLog (@"....");
NSUInteger row = indexPath. row;
[Self. editArray removeObjectAtIndex: row];
[TableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation :( UITableViewRowAnimationTop)];
}
Else

{

NSArray * insertIndexPaths = [NSArray arrayWithObjects: indexPath, nil];

 


// Similarly, add the data to the list and use the row
[Self. list insertObject: @ "newly added row" atIndex: row];
[TableView insertRowsAtIndexPaths: insertIndexPaths withRowAnimation: UITableViewRowAnimationRight];

 


}


// Collect data updates
// [Self replaceCurrentViewData: self. editArray];


}

 

 


4: Mark:

 

-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath

{
UITableViewCell * oneCell = [tableView cellForRowAtIndexPath: indexPath];
If (oneCell. accessoryType = UITableViewCellAccessoryNone ){
OneCell. accessoryType = UITableViewCellAccessoryCheckmark;
} Else
OneCell. accessoryType = UITableViewCellAccessoryNone;
[TableView deselectRowAtIndexPath: indexPath animated: YES];
}

 

 

Else {
// We insert a row at the position of the selected row, so the indexPath parameter is directly used.
NSArray * insertIndexPaths = [NSArray arrayWithObjects: indexPath, nil];
// Similarly, add the data to the list and use the row
[Self. list insertObject: @ "newly added row" atIndex: row];
[TableView insertRowsAtIndexPaths: insertIndexPaths withRowAnimation: UITableViewRowAnimationRight];
}

 

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.