像[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.
*/
}
}
你可以發佈更多的代碼,請 – LostPuppy