[英]tableview static cell dynamic footer
I have a static cell with 2 sections. 我有一个包含2个部分的静态单元格。 One section has 2 rows and the other has a single row.
一节有两行,另一节只有一行。 One of the cells in the first section perform an operation that could take up to a minute (decrypting lots of data from the database then encrypting it again.
第一部分中的一个单元执行的操作可能要花费一分钟的时间(从数据库中解密大量数据,然后再次对其进行加密。
In order to inform the user that the operation is ongoing and not stuck, I am trying to do the following: (The below is a pseudo of my actual code) 为了通知用户该操作正在进行中且未卡住,我尝试执行以下操作:(以下是我的实际代码的伪内容)
Issue: 问题:
the footerString
in doStuff
is not shown. 没有显示
doStuff
的footerString
。 However the one in callDoStuff
is shown just fine... Any ideas what am I doing wrong? 但是
callDoStuff
中的callDoStuff
显示得很好...有什么主意我做错了吗?
- (void) doStuff
{
for (int i=0; i<[resultsArray count]; i++)
{
rec1 = [decrypt record1];
footerString = [@"Preparing item : " stringByAppendingString:rec1];
[self.tableView reload];
rec2 = [decrypt record2];
...
...
...
rec10 = [decrypt record10];
}
}
doStuff
is called from another function 从另一个函数调用
doStuff
- (void) callDoStuff
{
[self doStuff];
footerString = @"Done preparing items";
[self.tableView reload];
}
I do have the following in my tableviewcontroller
我的
tableviewcontroller
确实有以下内容
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section == 0)
return footerString;
else
return @"";
}
You should make your calculation in a background thread. 您应该在后台线程中进行计算。 Here you assign a new value to your UILabel, but the main thread has no time to refresh the view.
在这里,您为UILabel分配了一个新值,但是主线程没有时间刷新视图。
- (void) callDoStuff
{
[self doStuff];
}
- (void)doStuff {
dispatch_async(dispatch_queue_create("myqueue", NULL) , ^(void) {
// Here you enter in another thread
for (int i=0; i<[resultsArray count]; i++)
{
rec1 = [decrypt record1];
dispatch_async( dispatch_get_main_queue(), ^{
// Here you send message to your UILabel in your main thread
footerString = [@"Preparing item : " stringByAppendingString:rec1];
});
[self.tableView reload];
rec2 = [decrypt record2];
...
rec10 = [decrypt record10];
}
dispatch_async( dispatch_get_main_queue(), ^{
// Here you send a callback
[self doOtherStuffAfterDoStuff];
});
});
}
- (void)doOtherStuffAfterDoStuff {
footerString = @"Done preparing items";
[self.tableView reload];
}
Then your UI should finely update while your devrypting stuff is ongoing. 然后,当您不断进行破坏性工作时,您的UI应该会很好地更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.