简体   繁体   中英

How to add NSMutableArray into Object?

I have UITableView and it add data from NSMutableArray.

So, I want to know how to add NSMutableArray into Object?

and I will add Object into UITableView.

Because I want use [tableData removeAllObjects];

But now I can only use [UITableView removeFromSuperview];

Thank you for your hand.

Kind Regard.

Use addObject to add an object in your NSMutableArray .

- (void)addObject:(id)anObject

Use the method as below.

[myMutableArray addObject:myObj];

Once you done with updating your array, call reloadData on UITableView instance.

[myTableView reloadData];

UITableView does not work the way i think you think it does. It does not have a collection of cells that you manually modify using add or remove function calls like an NSArray. UITableView requires an object that serves as a delegate.

The tableview will "ask" the delegate "questions" about the content it should have (number of cells, sections, contents and types of cells), and the object will respond using the behavior you defined by implementing the UITableViewDataSource (and optionally UITableViewDelegate) protocol methods.

Here's a tutorial that should give you an understanding of what a tableview requires to have the contents you want it to have.

And here's what you should do further if the above tutorial did not work for you:)

What kind of object your tableData is? UITableView should have a delegate of kind UITableViewSourceData which provides it with data. Usually it's a controller that contains this UITableView . When UITableView has to draw the cell it call the delegate method:

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

which your delegate has to implement. You create some array/dictionary object to keep your data and feed it into cell, when asked.

If your tableData is NSMutableArray already, you can call on it removeAllObjects . What do you mean by adding it to Object? if you want to see the change in your table, just call [<name of your table instance> reloadData]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM