4

我正在尝试创建一些东西来列出连接到设备的所有用户 Twitter 帐户UIActionSheet。例如,我的设备上有三个 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数组转换为 ava_list作为UIActionSheet init...方法的参数传入,或 B.) 指定取消按钮应显示在单独的“部分”中?

4

1 回答 1

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]];
}
于 2014-03-07T02:22:46.023 回答