2012-06-27 3 views
0

UITableView를 채우는 데 사용하는 웹 서비스에서받은 배열 객체가 있습니다. 내가 webservice에서 새 배열을 가져오고 테이블을 채우고 다음이 배열에서 새 개체를 사용하려면 tableView 다시로드 내 배열을 재정의하는 메서드를 구현하는 중이 야. 이 일해야하는 방법입니다 :Reload UITableView 데이터가 제대로 작동하지 않습니다.

WSCaller *caller = [[WSCaller alloc]init]; 

    arrayFromWS = [caller getArray]; 
    [self.table reloadData]; 

을하고 작동하지 않습니다. 어떤 아이디어?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

NSString *CellIdentifier = @"productsCellIdentifier"; 

ProductsCell *cell = nil; 

cell = (ProductsCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (!cell) 
{ 
    NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"ProductsCell" owner:nil options:nil]; 

    for (id currentObject in topLevelObjects) 
    { 
     if ([currentObject isKindOfClass:[ProductsCell class]]) 
     { 
      cell = (ProductsCell *)currentObject; 
      break; 
     } 
    } 
} 

if (productsMutableArray) 
{ 
    cell.backgroundColor = [UIColor whiteColor]; 
    cell.productName.text = [[self.productsMutableArray objectAtIndex:indexPath.row]objectForKey:@"name"]; 

} 

return cell; 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [productsMutableArray count]; 
} 
+0

정확히 어떤 나던 작업 –

+0

변경'self.table' :

이 문제를 해결하려면, 나는 (당신의 productsMutableArray이/보유 재산 강력한이라고 가정처럼 뭔가를 위해 위의 코드를 변경하는 것이 좋습니다 것 'self.tableView'. – gtmtg

+0

배열의 새 객체로'tableView'를 업데이트하지 않습니다. –

답변

0

데이터 소스 구현이 잘못되었습니다 (또는 적어도 스 니펫이 있음).

첫째, 당신은 arrayFromWS 유지되지 않습니다

WSCaller *caller = [[WSCaller alloc] init]; 
arrayFromWS = [caller getArray]; 
[self.table reloadData]; 

둘째, 당신의있는 tableView에 : numberOfRowsInSection : 그리고있는 tableView : cellForRowAtIndexPath : 방법, 당신은 다른 배열 (productsMutableArray)를 사용하고 있습니다. ?

WSCaller *caller = [[WSCaller alloc] init]; 
self.productsMutableArray = [NSMutableArray arrayWithArray:[caller getArray]]; 
[self.table reloadData]; 
+0

arrayFromWS는 단지 추상적이라고 생각합니다. wev 서비스로부터받은 배열의 이름. 테이블 뷰 대리자 및 데이터 소스 메서드의 코드 조각을 복사하여 실제 코드에서 붙여 넣었습니다. – Morion

+0

예, 정확하게 그 것입니다. –

+0

배열을 사용하여'tableView'를 작성하는 방법은 문제가 없습니다. 새로운 객체로 배열을 변경하는 방법도 좋습니다. 내가 필요로하는 것은'tableView'를 다시로드하는 방법입니다. 'cellForRowAtIndexPath :'를 다시 호출해야하는데, 왜냐하면'tableView '를 채우는 데 사용하는 배열의 값이 변경 되었기 때문입니다. –

관련 문제