动态UIActionSheet'otherButtonTitles:'

时间:2014-03-07 02:09:16

标签: ios twitter uiactionsheet acaccount

我正在尝试创建一些内容,列出UIActionSheet中连接到设备的所有用户的Twitter帐户。例如,我的设备上有三个Twitter帐户。我希望操作表能够使用取消按钮列出我的帐户。目前,我的功能如下:

- (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作为UIActionSheet init...方法的参数传入,或者B 。)指定取消按钮应显示在单独的“部分”中吗?

1 个答案:

答案 0 :(得分: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]];
}