Hai Charoenmit
Hai Charoenmit

Reputation: 71

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.

Upvotes: 0

Views: 306

Answers (3)

Nava Carmon
Nava Carmon

Reputation: 4533

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]

Upvotes: 0

Zaky German
Zaky German

Reputation: 14334

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 :)

Upvotes: 1

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

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];

Upvotes: 1

Related Questions