今天寫個function,是多個request發出去後,若沒有回應,則Alert個訊息出來,所以很簡單的如下寫了
UIAlertView *_alert = [[UIAlertView alloc] initWithTitle: @"提醒" message: @"網路連線有問題" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
_alert.delegate = self; //這個應該是多餘的
[_alert show];
[_alert release];
因為是多個request可能都回傳fail,所以先設定這個class實作UIAlertViewDelegate再改成
if (__alerting == NO) {
__alerting = YES;
UIAlertView *_alert = [[UIAlertView alloc] initWithTitle: @"提醒" message: @"網路連線有問題" delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
_alert.delegate = self;
[_alert show];
[_alert release];
}
- (void)alertViewCancel:(UIAlertView *)alertView
{
NSLog(@"Cancel!!");
__alerting = NO;
}
本以為這樣是ok的,試半天都無效,看到另一個function: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex,想想該不會預設cancel按鈕是index 0,alertViewCancel是另外一件事吧,再寫出
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"button index: %i",buttonIndex);
if (buttonIndex == 0) {
__alerting = NO;
}
}
這次就如我所想的了,回頭看alertViewCancel這function,找了找文件,才知道這是system去呼叫的....莫名其妙浪費一堆時間 orz
沒有留言:
張貼留言