如何推视图控制器(视图控制器)? [英] How to push viewcontroller ( view controller )?

查看:134
本文介绍了如何推视图控制器(视图控制器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内存管理在iPhone中是一个非常重要的问题。所以我问一个非常笼统的问题。
有两种方法可以调用另一个类的viewController。

Memory management is a very important issue in iPhone. So I am asking a very general question. There are two ways to call a the viewController of another class.

方法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?

So the obvious question is, which is the best way to call the viewController of other class ? Way1 or Way2?

公开邀请建议和意见。

请评论并投票。

推荐答案

方式1更简单。

控制器保持对推动的视图控制器的引用。如果你需要这个参考,那么这将是有用的。

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.

这篇关于如何推视图控制器(视图控制器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆