【发布时间】:2014-05-20 15:11:03
【问题描述】:
我正在向主视图添加一个子视图,但我无法从该视图中删除它。
NextViewController *nextView = [[NextViewController alloc] init];
nextView.transitioningDelegate = self;
nextView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.presentedViewController.view addSubview:nextView.view];
nextView.view.frame = CGRectMake(724, 80, 300, 150);
UIButton *stayButton = [[UIButton alloc] initWithFrame:CGRectMake(101, 94, 90, 49)];
[stayButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[stayButton setTitle:@"Detener" forState:UIControlStateNormal];
[stayButton addTarget:self
action:@selector(waitForNextView)
forControlEvents:UIControlEventTouchUpInside];
[nextView.view addSubview:stayButton];
stayButton.titleLabel.font = [UIFont systemFontOfSize:25];
[stayButton setTitleColor:[UIColor colorWithRed:(255/255.0) green:(255/255.0) blue:(255/255.0) alpha:1] forState:UIControlStateNormal];
这里我在视图中添加了一个按钮,然后当按下按钮时它就会消失`-
(void)waitForNextView{
transition = NO;
NextViewController *nextView = [[NextViewController alloc] init];
SectionViewController *sectionView = [[SectionViewController alloc]init];
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
actualSection = 0;
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(dismissView2) userInfo:nil repeats:NO];
}
我试过了:
[nextView.view removeFromSuperView];
[nextView.presentedViewController removeFromParentViewController];
但我不知道我还能做什么:S
如果您想了解更多信息,nextView 是一个 300x100 大小的 UIViewController。我想展示它,然后在我按下按钮时将其移除,仅此而已。
如果有人可以帮助我,我会很棒。
谢谢
【问题讨论】:
-
发布您尝试调用的 dissmissView2 方法 [nextView.view removeFromSuperView];
-
您要删除哪个视图?是按钮还是要删除 NextView?如果 NextView 是 UIViewController 子类,要关闭它,请使用
dismissViewControllerAnimated:completion:
标签: ios objective-c uiviewcontroller addsubview