2014-02-26 89 views
0

我得到的服務數據,我成功地解析這樣哪些錯誤與我的功能

-(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錯誤壞訪問。任何人都可以告訴我爲什麼?

+3

給我們您的numberOfRowsInSecti在代碼:) – rdurand

+1

和完整的錯誤文本 – rdurand

+1

'callWebService:'方法是同步還是異步? – Akhilrajtr

回答

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; 
    } 
+0

完美工作。 thankss – user3355452

0
return dataArray 

在你的函數在numberOfRowsInSection最後

使用本...

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