Push and Pop 行为很奇怪,为什么? [英] Push and Pop behaviour is strange, why?

查看:27
本文介绍了Push and Pop 行为很奇怪,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个类,一个是 addAlarm,第二个是 Name,,,

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

现在我在 addAlarm 中(addAlarm 是 UITableViewController 的子类),因为它选择了行,然后它转到 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;

然后就是UINavigationBar,默认是addAlarm作为返回按钮,而Name也是UITableViewController的子类

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

我观察到,当我单击 Name 中的 addAlarm 后退按钮时,它会返回到 addAlarm,并调用其 viewWillAppear 方法,但之后它会调用

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

         - (void)dealloc

名称类.

我无法理解为什么它在执行 addAlarm 的 ViewWillApear 之后调用 Name 的方法,有什么想法吗?

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

推荐答案

您可以在下面的方法中传递数据,而不是在 dealloc 方法中传递数据.

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

-(void)viewWillDisappear:(BOOL)animated{

}

另一种方法是将其存储在 appDelegate 文件中,如下所示.

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

在 appDelegate.h 文件中

In appDelegate.h file

NSString *strName;

@property (nonatomic, 保留) NSString *strName;

@property (nonatomic, retain) NSString *strName;

在 appDelegate.m 文件中

In appDelegate.m file

@synthesize strName;

现在,您可以在 NameController 中创建 Application 对象,如下所示

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

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

并像这样存储价值

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

希望对您有所帮助.

这篇关于Push and Pop 行为很奇怪,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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