对UITableviewcell使用NSMutableArray

对UITableviewcell使用NSMutableArray,uitableview,ios6,nsmutablearray,uitextfield,Uitableview,Ios6,Nsmutablearray,Uitextfield,我正在尝试使用NSMutableArray来构建tableview的数据源。NSMutableArray为空 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.ingredientsArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView

我正在尝试使用NSMutableArray来构建tableview的数据源。NSMutableArray为空

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [self.ingredientsArray count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [self.ingredientsArray objectAtIndex:indexPath.row];

    return cell;
}
我有一个“添加”按钮,用户可以在文本字段中输入他们的成分,这将添加到数组中。加载数组没有什么问题。cell.textLabel.text=[self.ingredientsArray objectAtIndex:indexPath.row]有问题;但我不能把我的手指放在上面。我在网站上看到了一些类似问题的答案,但它们似乎不起作用。我尝试将numbersinrow:方法更改为一个值,但应用程序无法编译

然后,我将一个对象添加到视图中的NSMutablearray中。将numberOfRowsinSection:method中的numberOfRowsinSection:method更改为1,并在cellForRowAtIndexPath:中保持不变,这样我就能够看到我输入的测试字符串。然而,这不是我想要的

我希望用户在文本字段中输入一个字符串(成分),并将其显示在下面的tableview中。现在,当我向NSMutableArray添加字符串时,它们不会显示在tableview中,只有一个测试字符串存在。它们被正确地添加,因为我已经记录下来检查


非常感谢您的任何帮助或建议

使用
NSMutableArray
UITableView

对于以下几点,如果你说是

1) 您已连接
UITableView
委托和数据源?i、 e.
tableView.delegate=self
tableView.datasource=self

2) 您的
NSMutableArray
在添加对象之前被分配

3) 您可以打印(NSLog)从
NSMutableArray
添加的对象吗。i、 e.
NSLog(@“计数%d”,[array Count])

4) 将对象添加到
NSMutableArray
后是否重新加载
UITableView
?i、 e.
[tableview重载数据]


5) 放置
UITableView
datasource的断点,它们是否调用?

是否尝试调用insertRowsAtIndexPaths:withRowAnimation:?1-In-(UIImage*)cellBackgroundForRowAtIndexPath:(NSIndexPath*)indepath。我有行NSInteger rowCount=[self tableView:[self tableView]numberofrowsin节:0];2-是的,我的nsmutablearray在使用前是alloc init'd。3-我可以打印数组,并且计数与预期一致。4)我没有重新加载tableview。5) 他们被称为。从我的问题中你可以看到,如果我做了上述更改(加载数组,将行数更改为1等),我可以看到输出。好的,如果你能用你正在做的向数组中添加成分的代码更新你的问题就好了。不确定,但添加时可能会出现一些问题。有一个带有相应方法的“添加”按钮。我没有加载视图中的alloc init。然后使用addObject方法。然后打印数组并记录计数。重要的是要注意,这是正确的预期工作。你对我该如何解决这个问题有什么想法吗。对于你的第1点,我已经向你展示了代码。就像我不应该和自己联系一样。