2015-11-18 29 views
0
- (IBAction)showActionSheet:(UIButton *)sender { 

     UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Select the operation to proceed?"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Create", @"Update", @"Duplicate", nil] ; 
      [actionSheet showInView:self.view]; 

} 

如果沒有選擇任何內容,自動選擇取消;基於計時器,例如, 5秒後景氣取消?如何在objective-c的actionSheet中自動選擇一個選項?

UIActionSheet不UIAlertController因爲我想使的iOS 7.1兼容的二進制文件

+0

我想如果u點擊之外,它會解僱自己 –

回答

3
[self.actionSheet dismissWithClickedButtonIndex:[self.actionSheet cancelButtonIndex] 
          animated:YES]; 

或者例如:

- (IBAction)showActionSheet:(UIButton *)sender { 

     UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Select the operation to proceed?"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Create", @"Update", @"Duplicate", nil] ; 
      [actionSheet showInView:self.view]; 
     [self performSelector:@selector(dismissActionSheet:) withObject:actionSheet afterDelay:5.0]; 
} 

-(void)dismissActionSheet:(UIActionSheet *)actionSheet{ 
    if(actionSheet){ 
     [actionSheet dismissWithClickedButtonIndex:[actionSheet cancelButtonIndex] 
    } 
} 
+0

上述爆料actionSheet;它說我沒有宣佈actionSheet,雖然我有: @interface ViewController:UIViewController 的標題 – MANICX100

+0

編輯上面的問題想要的結果是一個計時器。 – MANICX100

+0

@ MANICX100,只需將對actionSheet的引用保存到ViewController的屬性即可。 – FreeNickname

相關問題