【问题标题】:What method is called after [self.navigationController popViewControllerAnimated:YES];?[self.navigationController popViewControllerAnimated:YES];之后调用了什么方法?
【发布时间】:2011-09-21 11:06:33
【问题描述】:

我有这个代码:

-(IBAction)OkButtonPressed:(id)sender{
    NSLog(@"BTN OK");
    RecherchePartenaireTableView *recherchePartenaireTableView=[[RecherchePartenaireTableView alloc]init];
    recherchePartenaireTableView.mytext=textFieldCode.text;

    [self.navigationController popViewControllerAnimated:YES];
}

按确定后,我在控制台中看到消息“BTN OK”,没有别的。在 RecherchePartenaireTableView 类中,我有方法 viewWillAppear、viewDidload... 和每个方法的 NSLog 消息。 [self.navigationController popViewControllerAnimated:YES];之后调用了什么方法?

【问题讨论】:

    标签: iphone methods viewwillappear


    【解决方案1】:

    如果您尝试设置类 RecherchePartenaireTableView 的属性,该属性已经在导航堆栈上,那么您通过创建它的新实例来做错了。

    您应该从 navigationController 堆栈中取回实例。

    改变

    RecherchePartenaireTableView *recherchePartenaireTableView=[[RecherchePartenaireTableView alloc]init];
    recherchePartenaireTableView.mytext=textFieldCode.text;
    

    NSArray *viewControllers = [self.navigationController viewControllers];
    RecherchePartenaireTableView *recherchePartenaireTableViewVC = (RecherchePartenaireTableView *)[viewControllers objectAtIndex:viewControllers.count - 2];
    recherchePartenaireTableViewVC.mytext=textFieldCode.text;
    

    viewDidAppear 方法将在您从中推送视图的类上调用。

    【讨论】:

    • 我找到了这个解决方案 [navigationController viewWillAppear:YES];在 viewDidLoad
    • 为什么 textFiledCode.text 为空?如何从 textField 中获取文本?...现在我遇到了这个问题:在 viewWillappear 上 mytext 为空,我不知道为什么:|
    • 你到底想做什么?从被推到它上面的类(您的按钮所在的类)中设置类RecherchePartenaireTableView 的属性(myText)?
    • 在 RecherchePartenaireTableView 我有属性 @property (nonatomic, retain) NSString *mytext;在 RecherchePartenaireTypePartenaireViewController 我有这个:-(IBAction)OkButtonPressed:(id)sender{ NSLog(@"BTN Ok"); RecherchePartenaireTableView *recherchePartenaireTableView=[[RecherchePartenaireTableView alloc] init]; recherchePartenaireTableView.mytext=cellText; NSLog(@"jjjjjj %@",recherchePartenaireTableView.mytext); [self.recherchePartenaireTableView.tableviewrecherchepartenaire reloadData]; [self.navigationController popViewControllerAnimated:YES]; }
    • 问题是在 viewwillAppear myText 是空的..为什么?
    【解决方案2】:

    如果您有一个控制器 A,并且您将控制器 B 推到 A 上。 所以在控制器 B 中调用 popViewControllerAnimated

    viewWillAppear:动画控制器 A 将被调用

    在您的情况下,B 是 RecherchePartenaireTableView,因此在执行 popViewController 时无法调用 B 的 viewWillAppear。

    如果你想在RecherchePartenaireTableView消失的时候做点什么,在RecherchePartenaireTableView的viewWillDisappear里做

    【讨论】:

    • 我想在 RecherchePartenaireTableView 被再次调用后给一个标签设置一个文本..
    • 您应该使用模型,因为您正在保存状态。如果您不想这样做,您可以在 appdelegeate 中创建一个状态变量,[(AppDelegate *)[UIApplication sharedApplication].delegate stateVar] = someValue,并在 viewWillAppear 中使用该值来设置文本
    【解决方案3】:
    - (void) viewWillAppear: (BOOL)animated method will be called first
    

    【讨论】:

    • 那为什么我没有收到来自 NSLog 的消息?
    • 如果不起作用,您可以使用 UINavigationControllerDelegate 方法调用 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多