崩溃错误:[__ NSCFArray objectAtIndex:]:索引(10)超出边界(10)'

时间:2015-05-13 01:51:27

标签: ios objective-c uitableview

我知道这似乎是一个相当常见的错误,但我会疯狂地试图理清为什么我收到这条消息。当我向下滚动tableView时,控制台会抛出这个:

由于未捕获的异常'NSRangeException'而终止应用程序,原因:' - [__ NSCFArray objectAtIndex:]:索引(10)超出边界(10)'

知道如何解决这个问题吗?我正在尝试获取数组storageData中的项目数(例如return [storageData count];)请参阅下面的代码。

ViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    self.storageData = [[NSMutableDictionary alloc] init];
    userName.text = [[[DIOSSession sharedSession] user] objectForKey:@"name"];
    emailAddress.text = [[[DIOSSession sharedSession] user] objectForKey:@"mail"];
    NSLog(@"%@", [[DIOSSession sharedSession] user]);

      NSMutableDictionary *viewParams = [NSMutableDictionary new];
      [viewParams setValue:@"storeditems" forKey:@"view_name"];
      [DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.descripData = responseObject;
          NSLog(@"%@",self.descripData);

     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Failure: %@", [error localizedDescription]);
     }];

    [DIOSNode nodeIndexWithPage:@"0" fields:@"title" parameters:[NSArray arrayWithObjects:@"storage_item", nil] pageSize:@"20" success:^(AFHTTPRequestOperation *operation, id responseObject) {

       __block int iCount = 0;

        for (id object in responseObject) {
        //    NSLog(@"adding object!");
            [self.storageData setObject:(NSDictionary *)object forKey:[NSString stringWithFormat:@"%d",iCount]];
            iCount++;

            [self.tableView reloadData];
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        //failure
    }];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [storageData count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *DoctorsTableIdentifier = @"StorageItemTableViewCell";

    StorageItemTableViewCell *cell = (StorageItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:DoctorsTableIdentifier];
    if (cell == nil)

        {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StorageItemTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

            NSDictionary *tmp = [self.storageData objectForKey:[NSString stringWithFormat:@"%d",(long)indexPath.row]];

        [[cell itemName] setText:(NSString *)[tmp objectForKey:@"title"]];

              NSString *title = [tmp objectForKey:@"title"];
              [[cell itemName] setText:title];


            NSDictionary *node = [self.descripData objectAtIndex:indexPath.row];
            [[cell itemDescrip] setText:[node objectForKey:@"body"]];


            NSString *secondLink = [[self.descripData objectAtIndex:indexPath.row] objectForKey:@"photo"];

            [cell.itemPhoto sd_setImageWithURL:[NSURL URLWithString:secondLink]];

              }

              return cell;
              }

0 个答案:

没有答案