开发者

Best way to call other class view in iphone?

开发者 https://www.devze.com 2022-12-28 01:15 出处:网络
Generally i call my other class view by creating a pointer of delegate and then call the other class by using its link as below:-

Generally i call my other class view by creating a pointer of delegate and then call the other class by using its link as below:-

First Way :-

Mydelegate *ptr = (Mydelegate *)[[UIApplication sharedApplication]delegate];

[self.navigationController pushViewController:ptr.NextClasspointer animated:YES];

Second Way :-

Create a pointer of that class which u want to call :--

NextClass *nextptr = [[NextClass alloc]initWithnibName:@"NextClass" bundle:nil];
[self.navigationController pushViewController:nextptr animated:YES];

[nextptr release];
nextptr = nil;

These above two methods i generally used but my problem is that which one is best for big project so that my stack problem will be removed I mean memory issue will be solved.And is it necessary to release pointer in first and secon开发者_运维问答d case is the way i release is correct or wrong

Please help me Thanks in Advance


In terms of memory management, there isn't a difference between these two - both enable you to either have memory leaks or not depending on the rest of your code!

However, bear in mind for either of these, each time your user wants to "drill down" another level in the navigation it will have to load the view from the nib file; conversely, each time they go "back up" the navigation stack these will be unloaded. Generally if my users are likely to be going up and down the navigation stack all the time I retain a single instance of the "child" view controller and push that back onto the stack whenever the user wants to go to it.

If you are having memory problems, I think it is likely caused by objects used by your NextClass not being released properly on unload/release. Double check that all objects that you're synthesizing/alloc'ing in the the NextClass object are being released in the ViewDidUnload method.

0

精彩评论

暂无评论...
验证码 换一张
取 消