在使用 SLRequest 时,有一些关于在 iOS 应用程序中发推文的精彩教程。然而,他们中的大多数人只是从 Twitter 帐户中提取最后一个对象。由于 iOS 设置中可以登录多个 Twitter 帐户,开发者是否需要在发推之前提供选择帐户的选项,还是只使用默认帐户?
最佳答案
您并非“必须”为用户提供选项,但建议您这样做。
我们的一个选择是像这样的操作表:
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 委托(delegate)方法中,检查按下了哪个操作表按钮:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != actionSheet.cancelButtonIndex) {
self.accountToUse = [_accounts objectAtIndex:buttonIndex];
}
}
这将根据用户选择的内容设置帐户。这是样板文件,可能需要根据您访问它的位置进行一些更改,但它在很大程度上是您所需要的!
希望对您有帮助!
关于ios - 在 SLRequest 上处理多个 Twitter 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14270670/