我的功能有什么问题

时间:2014-02-26 10:59:03

标签: ios iphone objective-c

我从服务中获取数据,我成功解析了这个

-(NSMutableArray *)clubTypes
{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    NSString *url = [NSString stringWithFormat:@"%@category",KWSURLList];
    NSLog(@"%@",url);
    NSDictionary * returnDict = (NSDictionary *) [self callWebService:url];
    if([returnDict objectForKey:@"result"])
    {
        //        NSDictionary * returnDictResult = (NSDictionary *) [returnDict objectForKey:@"result"];
        NSArray *returnedArray = [returnDict objectForKey:@"data"];

        for(NSDictionary *clubDict in returnedArray)
        {
            ClubTypeDC *clubDC = [[ClubTypeDC alloc] init];
            clubDC.clubTypeID = [[clubDict objectForKey:@"Id"] intValue];
            clubDC.clubTypeTitle = [clubDict objectForKey:@"tittle"];
            clubDC.clubTypeImage = [clubDict objectForKey:@"icons"];
            [dataArray addObject:clubDC];
            //            NSLog(@"%@",proEvents.proEventImage);
        }

    }

}

但我总是在numberOfRowsInSection中获得错误访问错误。谁能告诉我为什么?

2 个答案:

答案 0 :(得分:1)

请记住,总是像这样返回你的数组

return dataArray;

我编辑了你的代码,请检查

 -(NSMutableArray *)clubTypes
    {
        NSMutableArray *dataArray = [[NSMutableArray alloc] init];
        NSString *url = [NSString stringWithFormat:@"%@category",KWSURLList];
        NSLog(@"%@",url);
        NSDictionary * returnDict = (NSDictionary *) [self callWebService:url];
        if([returnDict objectForKey:@"result"])
        {
            //        NSDictionary * returnDictResult = (NSDictionary *) [returnDict objectForKey:@"result"];
            NSArray *returnedArray = [returnDict objectForKey:@"data"];

            for(NSDictionary *clubDict in returnedArray)
            {
                ClubTypeDC *clubDC = [[ClubTypeDC alloc] init];
                clubDC.clubTypeID = [[clubDict objectForKey:@"Id"] intValue];
                clubDC.clubTypeTitle = [clubDict objectForKey:@"tittle"];
                clubDC.clubTypeImage = [clubDict objectForKey:@"icons"];
                [dataArray addObject:clubDC];
                //            NSLog(@"%@",proEvents.proEventImage);
            }

        }
    return dataArray;
    }

答案 1 :(得分:0)

 return dataArray 
最后在你的函数中

在numberOfRowsInSection中使用它...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
    if ([dataArray count] > 0) {
       return dataArray.count;
    }
    else {
       return 0;
    }
}