2012-11-01 86 views
0

嗨我想通過以下方法創建一個動態tableView。但是在模擬器執行期間出現錯誤。它與預先聲明的NSArray一起工作,但以下方法不起作用。你能幫我解決這個問題嗎?添加項到一個tableView?!

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; 
} 
相關問題