2012-11-01 6 views
0

안녕하세요, 저는 다음과 같은 방법으로 동적 tableView를 만들려고합니다. 하지만 시뮬레이터를 실행하는 동안 오류가 발생합니다. 미리 선언 된 NSArray 함께 작동하지만 다음 메서드는 작동하지 않습니다. 이 주제에 대해 저를 도울 수 있습니까? 내가 믿을테이블 뷰에 항목 추가?

NSMutableArray *mesProduits; 
mesProduits = [[NSMutableArray alloc] init]; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellule]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:cellule]; 
    } 
    for(int index = 0; index < [myObjectsFormulas count]; index = index+13) 
    { 
     monTest = [myObjectsFormulas objectAtIndex:monIndex]; 
     monIndex = monIndex+13; 
     [mesProduits addObject:monTest]; 

    } 
    NSString *celltext1 = [mesProduits objectAtIndex:indexPath.row]; 
    cell.textLabel.text = celltext1; 

답변

0

cellForRowAtIndexPath 방법은 다음 다음과 같이 할 수 있습니다 :

// Declare mesProduits as a property 

- (void) viewDidLoad { 

    // Initialize and assigned values to monIndex and myObjectsFormulas 

    self.mesProduits = [[NSMutableArray alloc] init]; 
    for(int index = 0; index < [myObjectsFormulas count]; index = index+13) 
    { 
     monTest = [myObjectsFormulas objectAtIndex:monIndex]; 
     monIndex = monIndex+13; 
     [self.mesProduits addObject:monTest]; 

    } 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellule]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:cellule]; 
    } 
    NSString *celltext1 = [self.mesProduits objectAtIndex:indexPath.row]; 
    cell.textLabel.text = celltext1; 
} 
관련 문제