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

查看:151
本文介绍了Push和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.

在appDeleg中ate.h文件

In appDelegate.h file

NSString *strName;

@property(nonatomic,retain)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和Pop的行为很奇怪,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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