Skip to content

Commit ddf16a2

Browse files
author
yangcb
committed
移动并更新指定Cell的操作
1 parent 5c267d8 commit ddf16a2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Examples/iOSExample/iOSExample/Weibo/ProfileViewController.m

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ - (void)viewDidLoad {
2222
[super viewDidLoad];
2323
// Do any additional setup after loading the view from its nib.
2424
[_tableView registerNib:[UINib nibWithNibName:@"ProfileTableViewCell" bundle:nil] forCellReuseIdentifier:@"profilecell"];
25-
marr = [NSMutableArray arrayWithObject:@"row-0"];
25+
marr = [NSMutableArray arrayWithObject:[NSMutableString stringWithFormat:@"row-0"]];
2626
}
2727

2828
- (void)addItem:(id)sender {
29-
[marr insertObject:[NSString stringWithFormat:@"row-%zd",marr.count] atIndex:0];
29+
[marr insertObject:[NSMutableString stringWithFormat:@"row-%zd",marr.count] atIndex:0];
3030
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
3131
}
3232

@@ -41,12 +41,14 @@ - (IBAction)removeItem:(id)sender {
4141

4242
- (IBAction)updateItem:(id)sender {
4343
NSIndexPath *indexPath = [_tableView indexPathForCell:[sender superview].superview];
44+
45+
NSMutableString *removedObj = [marr objectAtIndex:indexPath.row];
46+
[removedObj appendString:@"更新"];
47+
[_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
4448
[_tableView beginUpdates];
45-
id removedObj = [marr objectAtIndex:indexPath.row];
4649
[marr removeObjectAtIndex:indexPath.row];
47-
[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
4850
[marr insertObject:removedObj atIndex:0];
49-
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
51+
[_tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
5052
[_tableView endUpdates];
5153
}
5254

0 commit comments

Comments
 (0)