我想顯示一個臨時警報約2秒鐘,以使用戶有機會取消操作。如果用戶點擊取消按鈕,後續的方法將不會被調用。但是,如果用戶未按取消,則將調用後續方法。任何人有任何想法如何使這項工作?在持續時間之後執行操作,如果沒有單擊alertView的buttonIndex
我有一個設置,看起來像這樣:
-(void) buttonPress {
//alert with message and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"2 seconds to cancel"
message:@"Push Cancel to stop" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:nil, nil];
alert.tag = 1;
[alert show];
return;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0 && alertView.tag == 1) {
//action cancelled
}
else {
//action not cancelled
}
}
當取消按鈕按下取消使用執行選擇器:'[NSObject的cancelPreviousPerformRequestsWithTarget:yourTarget選擇器:aSelector對象:anArgument];' – Wain
@BhaveshNai - 無2意味着2秒。 – Rohan
哦對不起@Rohan –