在初始化视图中按选项卡项目时重新加载uiview [英] Reload uiview when pressing tab item inside initialized view
问题描述
我在标签栏控制器中有一个视图控制器.当我进入"初始化视图时,我希望能够再次按下选项卡栏项并重新绘制视图.
I have a view controller inside a tab bar controller. When I'm "inside" the initialized view I want to be able to press the tab bar item again and redraw the view.
我的tabbarcontroller是在AppDelegate中创建的
My tabbarcontroller is created in the AppDelegate
#AppDelegate.m
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSString *titleV = viewController.title;
if (titleV == @"Random") {
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[detailViewController reloadView];
}
}
#ViewController.m
-(void)reloadView{
[self.view setNeedsDisplay];
NSLog(@"view updated");
}
//code
- (void)viewDidLoad
{
[super viewDidLoad];
[self checkContent];
NSLog(@"viewDidLoad");
}
//code
-(void)checkContent{
if (theContent==NULL) {
contentText.numberOfLines=0;
contentText.text = randomContent;
NSLog(@"%@", contentText.text);
} else {
contentText.text = theContent;
}
}
从日志中,我可以看到contentText.text得到了更新,尽管可见标签直到我移至另一个视图然后再次返回时才更新.我不确定为什么这行不通.任何有关如何解决此问题的想法都将受到赞赏.
From the log I can see that contentText.text gets updated though the visible label does not until I move to another view and then back again. I'm not sure why this isn't working. Any ideas on how to solve this are greatly appreciated.
如果您需要更多代码,我很乐意提供.
If you need more code I'd be happy to provide it.
干杯,Dubbelsnurr
Cheers, Dubbelsnurr
推荐答案
我不是将-tabBarController:didSelectViewController
放入appDelegate,而是将tabBarController子类化,并符合 UITabBarDelegate 代码>,然后从其中调用
-tabBarController:didSelectViewController
.
Instead of putting - tabBarController:didSelectViewController
in appDelegate, I would sub-class my tabBarController and conform to UITabBarDelegate
, and call - tabBarController:didSelectViewController
from within that.
这是一个实现类似概念的教程:
Here is a tutorial that implements a similar concept:
这篇关于在初始化视图中按选项卡项目时重新加载uiview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!