相关疑难解决方法(0)

如何正确使用insertRowsAtIndexPaths?

我在网上浏览了所有的例子,无法弄清楚如何正确地将一个单元格添加到带动画的tableview中.假设我有一个部分有一个单元格,我想在用户点击第一个单元格的附件后添加另一个单元格.

我的"添加"方法执行此操作:

- (IBAction) toggleEnabledTextForSwitch1onSomeLabel: (id) sender {  
if (switch1.on) {

    NSArray *appleComputers = [NSArray arrayWithObjects:@"WWWWW" ,@"XXXX", @"YYYY", @"ZZZZ", nil];
    NSDictionary *appleComputersDict = [NSDictionary dictionaryWithObject:appleComputers forKey:@"Computers"];
    [listOfItems replaceObjectAtIndex:0 withObject:appleComputersDict];
    [tblSimpleTable reloadData];

}
Run Code Online (Sandbox Code Playgroud)

哪个有效,但没有动画.我知道为了添加动画,我需要使用insertRowsAtIndexPaths:withRowAnimation,所以我尝试了很多选项但是在执行insertRowsAtIndexPaths:withRowAnimation方法时它总是崩溃.

我最近的尝试是通过这样做:

- (IBAction) toggleEnabledTextForSwitch1onSomeLabel: (id) sender {  
if (switch1.on) {

    NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0]; //ALSO TRIED WITH indexPathRow:0
      NSArray *indexArray = [NSArray arrayWithObjects:path1,nil];   
     [tblSimpleTable insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationRight];

}
}  
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我怎样才能轻松实现这一目标?我不明白这整个indexPathForRow的事情......我也不明白如何使用这种方法我可以为新单元格添加标签名称.请帮忙......谢谢!!

iphone xcode objective-c uitableview

33
推荐指数
3
解决办法
5万
查看次数

在iphone的TableView中动态添加一行

当我在表格中选择一行时,我需要在tableview中添加一个新行.

我想使用以下方法???

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Run Code Online (Sandbox Code Playgroud)

我在方法中写了什么来添加新行.

请帮帮我

提前谢谢Shibin.

iphone row tableview

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

iphone ×2

objective-c ×1

row ×1

tableview ×1

uitableview ×1

xcode ×1