2014-03-07 71 views
4

我正在嘗試創建一些內容,以列出與UIActionSheet中的設備連接的所有用戶的Twitter帳戶。例如,我的設備上有三個Twitter帳戶。我希望操作說明書使用取消按鈕列出我的帳戶。目前,我的功能如下所示:Dynamic UIActionSheet'otherButtonTitles:'

- (void)showAlertViewForAccounts:(NSArray*)accounts { 
    accounts = _.arrayMap(accounts, ^id(ACAccount *account) { 
     return account.username; 
    }); 

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose an account:" 
                  delegate:self 
                cancelButtonTitle:@"Cancel" 
               destructiveButtonTitle:nil 
                otherButtonTitles:nil]; 
    for (NSString *username in accounts) { 
     [actionSheet addButtonWithTitle:username]; 
    }  


    [actionSheet showInView:[[[[[UIApplication sharedApplication] delegate] window] rootViewController] view]]; 
} 

我的問題是,取消按鈕不顯示在操作表單獨的「部分」中。

反正是有,我可以A.)的accounts數組轉換成va_list作爲UIActionSheetinit...方法的參數被傳入,或B.)指定取消按鈕應在一個單獨的「部分被顯示「?

回答

13

添加取消按鈕別人之後:

- (void)showAlertViewForAccounts:(NSArray*)accounts { 
    accounts = _.arrayMap(accounts, ^id(ACAccount *account) { 
     return account.username; 
    }); 

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose an account:" 
                  delegate:self 
                cancelButtonTitle:nil 
               destructiveButtonTitle:nil 
                otherButtonTitles:nil]; 
    for (NSString *username in accounts) { 
     [actionSheet addButtonWithTitle:username]; 
    }  

    actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"]; 

    [actionSheet showInView:[[[[[UIApplication sharedApplication] delegate] window] rootViewController] view]]; 
} 
+0

真棒。感謝您及時的回覆! – HighFlyingFantasy

+0

@JoeBlow - 用這麼多的代碼發佈你自己的答案會更好,而不是將它全部添加到我的答案中。 – rmaddy