woz*_*woz 2 objective-c uitableview ios
我有一个关闭的应用程序,并在UITableViewCell触摸时转到Safari打开URL .当我回到应用程序时,仍然会选择单元格几秒钟.为什么不立即取消选择?这是一个错误吗?这是代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.section == 0 && indexPath.row == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.example.com/"]];
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试移动[tableView deselectRowAtIndexPath:indexPath animated:NO];到顶部并关闭动画,但它没有帮助.这不是什么大不了的事,但如果可能的话,我希望立即取消选择.
这也发生UIButton了.返回应用程序后,它会在突出显示状态下保留一两秒钟.
更改类似于[tableView deselectRowAtIndexPath:indexPath animated:NO];在下一次迭代中通过运行循环生效.退出时openURL:会延迟下一次迭代,直到您切换回应用程序.切换回来是通过在您离开之前在屏幕图像中循环来实现的,然后片刻之后再次使应用程序交互.因此,所选图像仍然存在.
将实现的细节放在一边,逻辑是影响屏幕内容的东西被捆绑在一起并且是原子的,这样当你进行视图调整时,你不必经常思考'哦不,如果框架重绘现在怎么办?只有这里的变化才能完成?' 根据iOS多任务模型,在您回到应用程序之前,不会发生调整界面的原子单位.
快速解决:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// deselect right here, right now
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.section == 0 && indexPath.row == 0) {
[[UIApplication sharedApplication]
performSelector:@selector(openURL:)
withObject:[NSURL URLWithString:@"http://www.example.com/"]
afterDelay:0.0];
/*
performSelector:withObject:afterDelay: schedules a particular
operation to happen in the future. A delay of 0.0 means that it'll
be added to the run loop's list to occur as soon as possible.
However, it'll occur after any currently scheduled UI updates
(such as the net effect of a deselectRowAtIndexPath:...)
because that stuff is already in the queue.
*/
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |