相关疑难解决方法(0)

如何判断UITableView何时完成了ReloadData?

我想在完成表演后滚动到UITableView的底部 [self.tableView reloadData]

我原本有

 [self.tableView reloadData]
 NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1) inSection: ([self.tableView numberOfSections]-1)];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
Run Code Online (Sandbox Code Playgroud)

但后来我读了reloadData是异步的,所以滚动不因为发生self.tableView,[self.tableView numberOfSections]并且[self.tableView numberOfRowsinSection都是0.

谢谢!

有什么奇怪的是我正在使用:

[self.tableView reloadData];
NSLog(@"Number of Sections %d", [self.tableView numberOfSections]);
NSLog(@"Number of Rows %d", [self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1);
Run Code Online (Sandbox Code Playgroud)

在控制台中它返回Sections = 1,Row = -1;

当我完成相同的NSLogs时,cellForRowAtIndexPath我得到Sections = 1和Row = 8; (8是对的)

objective-c uitableview reloaddata

167
推荐指数
8
解决办法
11万
查看次数

UICollectionView reloadData似乎缓慢/滞后(不是瞬时的)

您好:我在我的应用程序中使用了一个集合视图,我注意到它需要比预期更长的刷新时间reloadData.我的集合视图有1个section,我用5 cell秒测试它(每个都有2个按钮和一个标签).我将一些日志放入我的代码中,以显示系统实际需要刷新多长时间.有趣的是,日志表明它的刷新速度比它快.例如,在设备上,它将花费约0.2秒(明显),但这里是日志:

0.007sreloadData调用的时间到第一次cellForItemAtIndexPath调用的时间

0.002s 每个单元要加载并返回

0.041sreloadData调用时间到返回单元格#5的时间

cellForItemAtIndexPath函数中没有任何特别密集的东西(基本上只是NSArrayindexPaths中找到一个包含3个值的字典row).即使我删除了这个并且只返回一个带有空白按钮的单元格,我也看到了相同的行为.

有没有人知道为什么会发生这种情况?顺便提一下,它只发生在物理设备(iPad Air)上.谢谢!

编辑#1

根据Per @ brian-nickel的评论,我使用了Time Profiler工具,并发现每次reloadData调用确实都会出现峰值.这是一个截图:

时间分析器

@ArtSabintsev,这是围绕reloadData调用的函数,后跟cellForItemAtIndexPath:

//Arrays were just reset, load new data into them
//Loop through each team
for (NSString *team in moveUnitsView.teamsDisplaying) { //CURRENT TEAM WILL COME FIRST

    //Create an array for this team
    NSMutableArray *teamArr = [NSMutableArray new];

    //Loop through all …
Run Code Online (Sandbox Code Playgroud)

objective-c reloaddata ios uicollectionview uicollectionviewcell

4
推荐指数
2
解决办法
6084
查看次数

仅在reloadData完成后调用函数

我有一个tableView并且需要tableView在重新加载后执行一个功能.我怎么知道是否reloadData已经完成?假设我有方法A填充tableView,一旦[tableView1 reloadData]完成,我想调用methodB.谁能帮我这个?我一直在寻找好几个小时......谢谢!

- (void) methodA
{

    NSString *URLa = [NSString stringWithFormat:@"http://www.website.com/page.php?
    v1=%@&v2=%@&v3=%@",v1, v2, v3];

    NSURL *url = [NSURL URLa];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    (void) [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [tableView1 reloadData];

}
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios

0
推荐指数
1
解决办法
8783
查看次数