سؤال

وإدارة الذاكرة هي قضية هامة جدا في اي فون. لذلك أنا أسأل سؤال عام جدا. هناك طريقتان لاستدعاء وviewController من فئة أخرى.

وطريقة 1:

AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];

[self.navigationController pushViewController:viewController animated:YES];

وطريقة 2:

    #import "AnotherClassViewController.h"

    @interface ThisClassViewController : UIViewController{

      AnotherClassViewController *myViewController;

    }

    @property (nonatomic, retain) AnotherClassViewController *myViewController;

    @end

    @implementation ThisClassViewController

    @synthesize myViewController;

    - (void) pushAnotherViewController{

    if(self.myViewController == nil){

    AnotherClassViewController *tempViewController = [[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil];

    self.myViewController = tempViewController;

    [tempViewController release];
    }
    [self.navigationController pushViewController:myViewController animated:YES];
    }

- (void)dealloc{
self.myViewController = nil;
}
@end

وهكذا السؤال الذي يطرح نفسه هو، الذي هو أفضل وسيلة لاستدعاء viewController من فئة أخرى؟ Way1 أو Way2؟

وتدعى

والاقتراحات والملاحظات علنا.

يرجى التعليق والتصويت.

هل كانت مفيدة؟

المحلول

Way 1 is simpler.

Way 2 lets the first controller keep a reference to the pushed view controller. If you need that reference, then this would be useful.

There is no clear answer here. It depends upon your needs. The general rule, of course, is to make the code as simple as possible, but no simpler.

نصائح أخرى

Hmm... To keep things simple, why not just:

MyViewController* viewController = [[MyViewController alloc] init];

[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top