0

I have two classes, the one is addAlarm and second is Name,,,

for now I am in addAlarm (addAlarm is subclass of UITableViewController), as it selects the row, then it goes to Name class as below

        Name *ob = [[Name alloc] initWithStyle:UITableViewStyleGrouped];
        [self.navigationController pushViewController:ob animated:YES];

        [ob release];
        ob = nil;

then there is UINavigationBar with addAlarm as back button by default, while Name is also subclass of UITableViewController

I observe that when I click addAlarm backbutton in Name, then it goes back to addAlarm, and its viewWillAppear Method calls, but after that it calls

         - (void)viewDidUnload

and

         - (void)dealloc

of Name Class.

I am unable to understand that why it is calling the methods of Name after it executes ViewWillApear of addAlarm, any Idea?

Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154
  • this is expected behavior. If you click on back button it should call viewDidUnload and dealloc method of class which you are leaving from. This is not the problem. – Deeps Jul 16 '11 at 12:17
  • but Deeps, how can I save data to delegate method and show in other class, while it is not calling its method before the next class? – Chatar Veer Suthar Jul 16 '11 at 12:19
  • It this question get solved, then problem will be solved, cz in ViewWillApear, I am calling [self.tableView reloadData] and it is now taking updated data because data updates in dealloc method of name, what should I do ? – Chatar Veer Suthar Jul 16 '11 at 12:20
  • you should not update data in dealloc !!! Only release objects there! – Felix Jul 16 '11 at 12:30

1 Answers1

1

Instead of passing data in dealloc method You can Pass data in below method.

-(void)viewWillDisappear:(BOOL)animated{

}

Another Method is to store it in appDelegate file like below.

In appDelegate.h file

NSString *strName;

@property (nonatomic, retain) NSString *strName;

In appDelegate.m file

@synthesize strName;

Now, you can create object of Application in your NameController like below

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 

And store value like this

appDelegate.strName = @"Value to be passed to addAlarm View"

Hope this help.

Deeps
  • 4,399
  • 1
  • 26
  • 27