Ios 将新的自定义单元格添加到UITableView的顶部
我尝试了更多的时间来搜索,但结果不是我想要的。我有一个自定义单元格的UITableView。还有一个按钮可以向UITableView添加新单元格。我可以添加新的单元格,但它将被添加到tableview的底部。这就是为什么,我无法感觉单元格是否被添加。所以我需要在桌面视图的顶部添加单元格。请帮助我Ios 将新的自定义单元格添加到UITableView的顶部,ios,iphone,uitableview,Ios,Iphone,Uitableview,我尝试了更多的时间来搜索,但结果不是我想要的。我有一个自定义单元格的UITableView。还有一个按钮可以向UITableView添加新单元格。我可以添加新的单元格,但它将被添加到tableview的底部。这就是为什么,我无法感觉单元格是否被添加。所以我需要在桌面视图的顶部添加单元格。请帮助我 而不是[self.firstArray addObject:@”“使用 [self.firstArray insertObject:@"" atIndex:0]; 在addnewmarkets:act
而不是
[self.firstArray addObject:@”“代码>使用
[self.firstArray insertObject:@"" atIndex:0];
在addnewmarkets:
action集合中
NSInteger row = 0;
在表格顶部显示新行
因此,最后将使用addNewComments
方法
-(IBAction)addnewRemarks:(id)sender
{
NSInteger row = 0;
NSInteger section = 0;
[self.firstArray insertObject:@"" atIndex:row];
NSIndexPath *myindexpath = [NSIndexPath indexPathForRow:row inSection:section];
// [selectedarray addObject:myindexpath];
[self.firstTableView beginUpdates];
[self.firstTableView insertRowsAtIndexPaths:@[myindexpath] withRowAnimation:UITableViewRowAnimationTop];
[self.firstTableView endUpdates];
}
在您的代码中NSInteger行=[self.firstArray count]-1代码>这意味着新项目将在最后一个索引中添加。共享您尝试过的代码。代码仍然在末尾添加。还有其他方法吗?非常感谢。。你真的节省了我的时间。
-(IBAction)addnewRemarks:(id)sender
{
NSInteger row = 0;
NSInteger section = 0;
[self.firstArray insertObject:@"" atIndex:row];
NSIndexPath *myindexpath = [NSIndexPath indexPathForRow:row inSection:section];
// [selectedarray addObject:myindexpath];
[self.firstTableView beginUpdates];
[self.firstTableView insertRowsAtIndexPaths:@[myindexpath] withRowAnimation:UITableViewRowAnimationTop];
[self.firstTableView endUpdates];
}