我想創建一個函數,當從不同的viewcontrollers調用時創建一個actionsheet。 問題是,雖然uiaction表被創建,我似乎無法執行任何指定的點擊操作。事實上委託永遠不會被調用。 單擊任何按鈕時,操作表被解除。UIActionsheet委託clickedButtonAtIndex永遠不會被調用
我對功能碼爲:
func shareAction(){
var sheet: UIActionSheet = UIActionSheet();
print("Calling share action!");
let title: String = "Tell friends, make plans";
sheet.title = title;
sheet.addButtonWithTitle("Cancel")
sheet.addButtonWithTitle("WhatsApp");
sheet.addButtonWithTitle("Facebook");
sheet.addButtonWithTitle("Message");
sheet.addButtonWithTitle("More");
sheet.cancelButtonIndex = 0;
sheet.delegate=self;
sheet.showInView(self.view)
}
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)
{
print("clicking the action sheet")
if(buttonIndex ==0){
print("this is 0")
}
這是其延伸NSObject的和UIActionSheetDelegate類內部。 我已經經歷了每一點文件,並難以理解是什麼導致了這個問題。
你沒有使用'UIAlertController'的原因?代替一個委託,您可以使用您添加的每個操作特定的完成塊。無論如何,UIActionSheet和UIAlertView都不贊成使用UIAlertController。 – keithbhunter
我試圖保持我的代碼與iOS 7兼容,並避免爲8及以上版本編寫不同的代碼。這不是一個強有力的理由,但由於alertview沒有以前的版本支持,我更喜歡使用uiactionsheet。 –
支持iOS 7的任何特定原因?絕大多數用戶已經開始使用9了。Xcode 8/iOS 10將放棄對iOS 7的支持,如果這改變了您的想法:[請參閱此鏈接](https://twitter.com/jamesthomson/status/747451011183280128) – keithbhunter