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

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

问题描述

内存管理是 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.

方式一:

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 的最佳方式是什么?方式一还是方式二?

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

公开邀请建议和评论.

请评论和投票.

推荐答案

方法 1 更简单.

方式 2 让第一个控制器保持对推送视图控制器的引用.如果您需要该参考,那么这将很有用.

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天全站免登陆