2013-01-11 46 views
2

在使用SLRequest时,在iOS应用程序中有一些关于Tweeting的优秀教程。但是,他们中的大多数人只是从Twitter帐户中提取最后一个对象。由于可以在iOS设置上登录多个Twitter帐户,开发者是否需要在Tweeting之前提供哪个帐户可供选择的选项,或仅使用默认值?在SLRequest上处理多个Twitter帐户

+0

你有没有找到解决方案? – chris

+0

[[SLComposeViewController]](https://developer.apple.com/library/ios/documentation/)[处理得好](https://dev.twitter.com/docs/ios/using-tweet-sheet) NetworkingInternet/Reference/SLComposeViewController_Class/Reference/Reference.html#// apple_ref/doc/uid/TP40012205)类。 – JaKXz

回答

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

    } 
} 

这将设置基于用户挑选什么样的帐户。这是样板文件,可能需要根据您访问的位置稍作更改,但它大部分都是您需要的!

希望它有帮助!