如何在ipad中的另一个ViewController中重新加载rootViewController [英] how to reload the rootViewController in another ViewController in ipad

查看:80
本文介绍了如何在ipad中的另一个ViewController中重新加载rootViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在splitViewController的RootViewController中设置userName标签文本,它可以正常工作,但问题是我想在otherViewController中更改userName标签文本,但是当我打开Root Viewcontroller时,它没有得到新的userName可能是由于它不会重新加载.

解决方案

首先,您需要设置一个全局变量以访问该变量,在此变量中您可以从另一个类中设置Username,然后可以使用以下方法在特定变量上设置Username./p>

您可以使用从其他类访问类方法@protocol

您可以将 NSNotificationCenter 用作波纹管

将贝娄方法添加到您的 rootViewcontroller ViewDidLoad 方法中:-

  [[NSNotificationCenter defaultCenter] addObserver:self选择器:@选择器(actionNotificationData :)名称:@"reloadData"对象:无];-(void)actionNotificationData:(NSNotification *)notification {//您的可变逻辑代码} 

并放置Bellow方法以调用 NSNotificationCenter ,从此处要调用reloadData rootViewcontroller

  [[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self]; 

I am setting the userName label text in RootViewController in splitViewController it works fine but problem is that I want to change the userName label text in otherViewController but when I open Root Viewcontroller it does not get the new userName may be due to it does not get reloaded again.

解决方案

First you need to set one global variable for accessing this where you set Username from another class and then you can use bellow methods for set Username on particular variable.

you can access class method from Other class using @protocol

or

You can use NSNotificationCenter as Bellow

Add Bellow Method into your rootViewcontroller ViewDidLoad method:-

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(actionNotificationData:)
                                                 name:@"reloadData"
                                               object:nil];

-(void)actionNotificationData:(NSNotification *)notification {

   //your code for variable logic

}

and put Bellow Method for calling NSNotificationCenter where from you want to calling reloadData rootViewcontroller

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];

这篇关于如何在ipad中的另一个ViewController中重新加载rootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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