2012-05-06 70 views
0

我添加从控制器A现在,在控制器B这是子视图控制器的子视图中删除子视图,我怎样才能重新加载视图一个当用户正与乙做什么?IOS从另一个控制器

ChangeProfileImage *changeProfileImage =[[ChangeProfileImage alloc] init]; 
    changeProfileImage.modalPresentationStyle = UIModalPresentationFormSheet; 
    changeProfileImage.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    changeProfileImage.view.frame = CGRectMake(50, 50, 300, 300); 
    UIView *dimBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds]; 
    dimBackgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f]; 
    [self.view addSubview:dimBackgroundView]; 
    [self.view addSubview:changeProfileImage.view]; 
+1

所以在控制器B ..你尝试'[self.view removeFromSuperView]'? –

+0

这可以删除changeprofileimage视图,但dimbackground视图又如何?以及如何刷新控制器A? – user2514963

+0

检查答案Plz。 –

回答

1

你可以设置一个标记为 “dimbackground” ..并删除它像这样:

dimBackgroundView.tag = 111;//you will do this line when you create the view. 
UIView *view = [controllerA.view viewWithTag:111]; 
[view removeFromSuperview]; 

刷新你的viewController:

当用户点击我加子视图的代码提交按钮,你删除B视图..使用NSNotificationCenter像这样发布通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"UserSubmit" object:nil]; 

和controllerA .. viewDidLoad中例如添加它作为观察员这样

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

,你会实现这个功能:

- (void) refreshView 
{ 
    //Do your stuff 
} 
+0

如何刷新控制器视图? – user2514963

+0

“刷新”是什么意思?当你喜欢这样做? –

+0

意味着用户点击提交B.然后重定向回到A与更新的值 – user2514963

0

创建与IBAction为视图控制器相连接给它的按钮,写下面在该按钮的IBAction为代码,这将移除的ViewController乙

[self.view removeFromSuperview];

+0

但A不刷新 – user2514963