【问题标题】:How to add NSMutableArray into Object?如何将 NSMutableArray 添加到对象中?
【发布时间】:2011-06-12 07:36:07
【问题描述】:

我有 UITableView,它从 NSMutableArray 添加数据。

那么,我想知道如何将 NSMutableArray 添加到 Object 中?

然后我会将 Object 添加到 UITableView 中。

因为我想使用 [tableData removeAllObjects];

但是现在我只能使用 [UITableView removeFromSuperview];

谢谢你的手。

亲切的问候。

【问题讨论】:

标签: ios4 ios-simulator iphone


【解决方案1】:

使用addObject 在您的NSMutableArray 中添加一个对象。

- (void)addObject:(id)anObject

使用如下方法。

[myMutableArray addObject:myObj];

完成数组更新后,在 UITableView 实例上调用 reloadData。

[myTableView reloadData];

【讨论】:

    【解决方案2】:

    UITableView 不像我认为的那样工作。它没有您使用添加或删除函数调用(如 NSArray)手动修改的单元格集合。 UITableView 需要一个对象作为委托。

    tableview 将“询问”委托“问题”关于它应该具有的内容(单元格、部分、内容和单元格类型),并且对象将使用您通过实现 UITableViewDataSource 定义的行为(以及可选 UITableViewDelegate) 协议方法。

    Here's a tutorial 这应该让您了解 tableview 需要什么才能拥有您想要的内容。

    如果上面的教程不适合你,你应该怎么做here's :)

    【讨论】:

      【解决方案3】:

      你的 tableData 是什么类型的对象? UITableView 应该有一个类型为 UITableViewSourceData 的委托,它为它提供数据。通常它是一个包含这个UITableView 的控制器。当 UITableView 必须绘制单元格时,它会调用委托方法:

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

      您的代表必须实现的。您创建一些数组/字典对象来保存您的数据并将其输入到单元格中,当被询问时。

      如果您的 tableData 已经是NSMutableArray,您可以调用它removeAllObjects。将它添加到对象是什么意思? 如果您想查看表格的变化,请致电[<name of your table instance> reloadData]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-25
        • 1970-01-01
        • 2014-05-25
        • 2015-08-29
        • 1970-01-01
        • 2012-11-29
        • 1970-01-01
        相关资源
        最近更新 更多