我在主視圖中添加了一個子視圖,但是我無法從這個視圖中刪除它。從UIViewController中刪除一個子視圖
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];
這裏我加入一個按鈕視圖,然後當按鈕被按下它goes`-
(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];
我不知道我還能做什麼:S
如果您需要更多信息,nextView是300x100大小的UIViewController。我想呈現它,然後在我按下按鈕時將其刪除,就這些了。
如果有人能幫助我,我會很棒。
感謝
郵政dissmissView2方法,你正試圖調用[nextView.view removeFromSuperView] ; – Yan
你想刪除哪個視圖?它是按鈕還是你想刪除NextView?如果NextView是一個UIViewController子類,使用'dismissViewControllerAnimated:completion:' – KerrM