Reload uiview when pressing tab item inside initialized view

China☆狼群 提交于 2019-12-11 07:26:16

问题


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.

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;
    }
}

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.

Cheers, Dubbelsnurr


回答1:


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:

http://iosdevelopertips.com/user-interface/detect-taps-on-uitabbarcontroller-and-determining-class-type.html



来源:https://stackoverflow.com/questions/9709519/reload-uiview-when-pressing-tab-item-inside-initialized-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!