2

在使用 SLRequest 时,有一些很棒的 iOS 应用程序中的 Tweeting 教程。然而,他们中的大多数只是简单地从 Twitter 帐户中提取最后一个对象。由于可以在 iOS 设置上登录多个 Twitter 帐户,开发人员是否需要在发推文之前提供一个选项来选择哪个帐户,或者只使用默认帐户?

4

1 回答 1

1

您不是“必须”为用户提供选项,但建议您这样做。

一种选择是给我们一个像这样的行动表:

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Choose an Account" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    for (ACAccount *acct in _accounts) {
        [sheet addButtonWithTitle:acct.username];
    }
    sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];
    [sheet showInView:self.view];

这假设您已经将帐户加载到一个数组中(我命名为我的 _accounts),而不是选择最后一个对象,而是使用此代码显示所有可用的帐户。

然后在您的 UIActionsheet 委托方法中,检查按下了哪个操作表按钮:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != actionSheet.cancelButtonIndex) {

        self.accountToUse = [_accounts objectAtIndex:buttonIndex];

    }
}

这将根据用户选择的内容设置帐户。这是样板文件,可能需要根据您访问它的位置进行一些更改,但它在很大程度上是您所需要的!

希望能帮助到你!

于 2013-07-22T21:39:10.923 回答