/*
__block void (^callback)() = [^{
float second = 2.0;
bool _stop = NO;
if(_stop) {
NSLog(@"all done");
callback = nil; // break retain cycle
} else {
NSLog(@"still going");
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
[dic setObject:object forKey:key];
[_service listMessages:^(id response, NSError *error) {
//获取主线程,更新界面
if (error) {
//show error
}else{
获取数据
}
dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
[table reloadData];
[self scrollTableToFoot];
});
}
} parameters:dic];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, second * NSEC_PER_SEC),
dispatch_get_main_queue(),
callback);
}
} copy];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC),
dispatch_get_main_queue(),
callback);
*/
__block void (^callback)() = [^{
float second = 2.0;
bool _stop = NO;
if(_stop) {
NSLog(@"all done");
callback = nil; // break retain cycle
} else {
NSLog(@"still going");
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
[dic setObject:object forKey:key];
[_service listMessages:^(id response, NSError *error) {
//获取主线程,更新界面
if (error) {
//show error
}else{
获取数据
}
dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
[table reloadData];
[self scrollTableToFoot];
});
}
} parameters:dic];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, second * NSEC_PER_SEC),
dispatch_get_main_queue(),
callback);
}
} copy];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC),
dispatch_get_main_queue(),
callback);
*/

本文介绍了一个使用Objective-C实现的延时回调机制,并在回调中通过主线程更新UI的过程。具体包括如何利用`dispatch_after`进行延时操作、在主线程中刷新表格视图及滚动到指定位置的方法。
2414

被折叠的 条评论
为什么被折叠?



