0

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.

1

3 Answers 3

1

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];
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.