Ios 将按钮添加到操作表时发生NSInvalidArgumentException

Ios 将按钮添加到操作表时发生NSInvalidArgumentException,ios,objective-c,ios5,uiactionsheet,Ios,Objective C,Ios5,Uiactionsheet,我正在尝试创建一个包含twitter帐户列表的操作表,但是在创建按钮的过程中出现了这个异常 NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' 这是一些重要方法的代码 //SocialNetworking.m文件 - (BOOL)loginWithTw

我正在尝试创建一个包含twitter帐户列表的操作表,但是在创建按钮的过程中出现了这个异常

NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
这是一些重要方法的代码

//SocialNetworking.m文件

- (BOOL)loginWithTwitterCompletionBlock:(UIView *)sender :(void (^)(User *,ACAccount *selAccount, NSError *))completionBlock
{
    ACAccountStore *store = [[ACAccountStore alloc] init];
    ACAccountType *twitterType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    [store requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
        NSArray *twitterAccounts = [store accountsWithAccountType:twitterType];

        if(twitterAccounts == nil || [twitterAccounts count] == 0) {
            NSMutableDictionary* details = [NSMutableDictionary dictionary];
            [details setValue:@"Account unavailable" forKey:NSLocalizedDescriptionKey];
            NSError *error=[NSError errorWithDomain:@"authentication" code:10 userInfo:details];

            completionBlock(nil,nil, error);

        } else {

                if (granted && !error)
                    {
                        twitterAccountsArray = [store accountsWithAccountType:twitterType];

                        if ([twitterAccountsArray count] > 1)
                        {

                            dispatch_sync(dispatch_get_main_queue(), ^{
                                [self accountListActionSheetDynamic:twitterAccountsArray Sender:sender];
                            });
                        }
                        else
                        {
                            selectedAccount = [twitterAccounts objectAtIndex:0];
                        }
                    }
NSURL *userDetailsURL=[NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"];
//Getting the exception in this line below
                NSDictionary *params = @{@"screen_name" : selectedAccount.username,
                                         @"entities" : @"0"};

            TWRequest *request = [[TWRequest alloc] initWithURL:userDetailsURL parameters:params requestMethod:TWRequestMethodGET];
            [request setAccount:selectedAccount];
            [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
             {
                if (responseData)
                {
                    NSError *error = nil;
                    NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];


                User *socialUser=[[User alloc] init];

                socialUser.twitterName=[responseDict valueForKey:@"name"];
                socialUser.twitterUserName=selectedAccount.username;
                socialUser.twitterProfileId = [responseDict valueForKey:@"id_str"];
                socialUser.twitterProfileImageURLString=[responseDict valueForKey:@"profile_image_url"];
                socialUser.twitterProfileBackgroundURLString=[responseDict valueForKey:@"profile_background_image_url"];


                completionBlock(socialUser,selectedAccount, nil);
            }

            else
                {
                completionBlock(nil,nil, error);
                }
        }];

}

//Action sheet For Multiple TwitterAccounts
- (void)accountListActionSheetDynamic:(NSArray *) accounts Sender:(UIView*) senderView {

    UIActionSheet *sheet = [[UIActionSheet alloc]
                            initWithTitle:@"Choose a Twitter Account"
                            delegate:self
                            cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                            otherButtonTitles:nil];

    for(int i=0;i<accounts.count;i++)
    {
        NSLog(@"i=%d,AccountName:%@",i,[[accounts objectAtIndex:i] valueForKey:@"username"]);
        [sheet addButtonWithTitle:[[accounts objectAtIndex:i] valueForKey:@"username"]]; 
    }
    [sheet addButtonWithTitle:@"Cancel"];
    sheet.cancelButtonIndex = sheet.numberOfButtons-1;

    [sheet showFromRect:senderView.bounds inView:senderView animated:YES];

}


-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.cancelButtonIndex)
    {
        return;
    }
    else
    {

     for(int i=0;i<twitterAccountsArray.count;i++)
        {
            if([[actionSheet buttonTitleAtIndex:buttonIndex] caseInsensitiveCompare:[[twitterAccountsArray objectAtIndex:i] valueForKey:@"username"]]==NSOrderedSame)
            {
                selectedAccount = [twitterAccountsArray objectAtIndex:i];

                return;
            }

        }
    }

}
-(BOOL)带有TwitterCompletionBlock的登录:(UIView*)发送方:(void(^)(User*,acacaccount*selcount,NSError*)completionBlock
{
ACAccountStore*store=[[acacaccountstore alloc]init];
ACAccountType*twitterType=[存储accountTypeWithAccountTypeIdentifier:AcAccountTypeIdentifierWitter];
[store requestAccessToAccountsWithType:twitterType with CompletionHandler:^(已授予BOOL,n错误*错误){
NSArray*twitterAccounts=[store accountsWithAccountType:twitterType];
如果(twitterAccounts==nil | |[twitterAccounts count]==0){
NSMutableDictionary*详细信息=[NSMutableDictionary];
[详细信息设置值:@“帐户不可用”forKey:NSLocalizedDescriptionKey];
N错误*错误=[N错误errorWithDomain:@“身份验证”代码:10用户信息:详细信息];
完成块(零,零,错误);
}否则{
如果(已授予&&!错误)
{
twitterAccountsArray=[store accountsWithAccountType:twitterType];
如果([twitterAccountsArray计数]>1)
{
调度同步(调度获取主队列()^{
[self-accountListActionSheetDynamic:twitterAccountsArray发件人:发件人];
});
}
其他的
{
selectedAccount=[twitterAccounts对象索引:0];
}
}
NSURL*userDetailsURL=[NSURL URLWithString:@”https://api.twitter.com/1.1/users/show.json"];
//获取下面这行中的异常
NSDictionary*params=@{@“屏幕名称”:selectedAccount.username,
@“实体”:@“0”};
TWRequest*request=[[TWRequest alloc]initWithURL:userDetailsURL参数:params requestMethod:TWRequestMethodGET];
[请求设置帐户:selectedAccount];
[请求性能请求处理程序:^(NSData*responseData,NSHTTPURLRResponse*urlResponse,NSError*error)
{
如果(响应数据)
{
n错误*错误=nil;
NSDictionary*responseDict=[NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableLeaves错误:&error];
User*socialUser=[[User alloc]init];
socialUser.twitterName=[responseDict valueForKey:@“name”];
socialUser.twitterUserName=selectedAccount.username;
socialUser.twitterProfileId=[responseDict valueForKey:@“id_str”];
twitterProfileImageURLString=[responseDict valueForKey:@“profile_image_url”];
twitterProfileBackgroundURLString=[responseDict valueForKey:@“profile\u background\u image\u url”];
完成块(socialUser,selectedAccount,无);
}
其他的
{
完成块(零,零,错误);
}
}];
}
//多个TwitterAccounts的操作表
-(void)accountListActionSheetDynamic:(NSArray*)帐户发件人:(UIView*)senderView{
UIActionSheet*工作表=[[UIActionSheet alloc]
initWithTitle:@“选择一个Twitter帐户”
代表:赛尔夫
取消按钮:无
破坏性按钮:无
其他按钮:无];
对于(int i=0;i尝试替换:

[accounts objectAtIndex:i] 
使用以前声明的(在此循环中)变量,例如-

NSString *name=[accounts objectAtIndex:i]
尝试替换:

[accounts objectAtIndex:i] 
使用以前声明的(在此循环中)变量,例如-

NSString *name=[accounts objectAtIndex:i]

放置异常断点以查看异常确切来自哪一行放置异常断点以查看异常确切来自哪一行