MainstreamDeveloper00
MainstreamDeveloper00

Reputation: 8556

How to reload UITableView when I add a new element to NSMutableArray in another class?

I have a singleton object which has ivar NSMutableArray which holds images global to application. And I have a UITableViewController class which represents image attaches to the message.I want to do next: when user select images from Camera Roll they are added to that singleton's array. And I want to reload tableview of my UITableViewController at once to display these new messages. How can I implement this? Should I use Key-Value Observing for this and if yes how can I do this? (I should notify when new object will be added to array). Or may be there are some other more correct way?

Upvotes: 0

Views: 220

Answers (3)

Ravi_Parmar
Ravi_Parmar

Reputation: 12329

i know exactly what u need to Do.Download this Demo for reference.

it has delegate method

    - (void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image{

     // add your code here for adding image to Your mutable array and then Reload your tableView.

      }

Upvotes: 1

kirti Chavda
kirti Chavda

Reputation: 3015

add notification in which class has table

 [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(actionremovecalender:)
                                                 name:@"subMitReport"
                                               object:nil];
-(void)actionremovecalender:(NSNotification *)notification
{
   //table relaod code
}
call to another class
 [[NSNotificationCenter defaultCenter] postNotificationName:@"subMitReport" object:self];

Upvotes: 0

Antonio MG
Antonio MG

Reputation: 20410

What about sending a NSNotification when you want the view to reload?

The UITableView can receives the notification and reload the data.

Upvotes: 0

Related Questions