动态UIActionSheet 'otherButtonTitles:'

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]];
}

我的问题是取消按钮没有显示在操作表的单独“section”中。

有没有办法将accounts数组转换为va_list,以便作为UIActionSheet init...方法的参数传递,或者指定取消按钮应该显示在单独的“section”中?

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]];
}

太棒了。感谢您的快速回复! - HighFlyingFantasy
@JoeBlow - 如果你有那么多的代码,最好是发布自己的答案,而不是把它全部添加到我的答案中。 - rmaddy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接