私はUIWindowのrootViewControllerである親ビューコントローラを持っています。そして、このUIViewControllerには2つのサブビューがあります(viewcontrollersが追加されました)。私は右側のサブビューコントローラのボタンをタップすると、モーダルビューを開く必要があります。右側のビューから[self presentModalView:vc]を使用してこれを実行しようとすると、UI全体が折りたたまれます。したがって、コードを変更しました。つまり、私はAppDelegateを通してparentViewControllerからモーダルビューを提示しました。 appdelegateにはparentViewのインスタンスがあるためです。私がこのようにすると、モーダルビューは問題なく表示されます。rootviewコントローラのサブビューコントローラからのモーダルビューとしてのUIViewControllerの提示に関する問題
私の質問ですが、正しいアプローチですか?モーダルビューを提示することについての明確な手続き/文書はありますか、そうではありませんか?
もう1つの問題に直面しています。私はこの最初のモーダルビュー上で別のモーダルビューを提示しようとすると動作しません。
私を明確にしてください。
編集:は、問題をシミュレートするコードサンプルを追加しました。 RootViewControllerがウィンドウに追加されます。 RightViewControllerは、ルートビューコントローラのサブビューです。右のビューコントローラのボタンをクリックすると、モーダルビューコントローラがモーダルビューとして表示されます。ここに問題があります。モーダルビューは正しく発生しません 。これがあなたに役立つことを願っています
- ありがとうございます。 @durai
#import <UIKit/UIKit.h>
@class RightViewController;
@interface RootViewController : UIViewController {
UIView *bgView;
RightViewController *rightView;
}
@end
#import "RootViewController.h"
#import "RightViewController.h"
@implementation RootViewController
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
- (void) loadView
{
bgView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
rightView = [[RightViewController alloc] init];
[bgView addSubview:rightView.view];
self.view = bgView;
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
// RightViewController.h
// ModalViewTester
//
//
#import <UIKit/UIKit.h>
#import "ModalViewController.h"
@interface RightViewController : UIViewController <ModalViewDelegate>{
UIView *rightView;
UIButton *button;
}
- (void) showModalView;
@end
#import "RightViewController.h"
@implementation RightViewController
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
- (void) loadView
{
rightView = [[UIView alloc] initWithFrame:CGRectMake(320, 40, 250, 250)];
rightView.backgroundColor = [UIColor yellowColor];
self.view = rightView;
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20, 20, 100, 30);
[button setTitle:@"Modal" forState:UIControlStateNormal];
[button addTarget:self action:@selector(showModalView) forControlEvents:UIControlEventTouchUpInside];
[rightView addSubview:button];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 50, 100, 50)];
label.text = @"Right View";
label.textColor = [UIColor blackColor];
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
[rightView addSubview:label];
self.view = rightView;
}
- (void) showModalView
{
ModalViewController *mc = [[ModalViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationFullScreen;
self.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:mc animated:YES];
[mc release];
}
- (void) closeView:(NSDictionary *)dict
{
[self dismissModalViewControllerAnimated:YES];
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
#import <UIKit/UIKit.h>
@protocol ModalViewDelegate
-(void) closeView:(NSDictionary *) dict;
@end
@interface ModalViewController : UIViewController {
UIView *modalView;
UIButton *cancelButton;
id <ModalViewDelegate> delegate;
}
- (void) closeView:(id) sender;
@end
#import "ModalViewController.h"
@implementation ModalViewController
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
- (void) loadView
{
NSLog(@"Inside ModalViewController - loadView method");
modalView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
modalView.backgroundColor = [UIColor blueColor];
cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(150, 50, 70, 40)];
[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelButton addTarget:self action:@selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
[modalView addSubview:cancelButton];
self.view = modalView;
}
- (void) closeView:(id) sender
{
[delegate closeView:nil];
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
私はあなたが何をしているのか推測する必要があります。したがって、私はあなたを助けることはできません。 – dasdom