2011-09-09 56 views
0

的子视图控制器呈现的UIViewController作为modalview我有一个父视图控制器,其是一个UIWindow的RootViewController的。而这个UIViewController有两个子视图(viewcontrollers添加)。当我点击右侧子视图控制器中的按钮时,它应该打开一个模态视图。当我尝试通过在右侧视图中使用[self presentModalView:vc]来做到这一点时,它会折叠整个UI。因此,我改变了代码,即我通过AppDelegate展示了parentViewController的模态视图。因为appdelegate有parentView的实例。当我喜欢这个模态视图出现没有任何问题。问题与来自rootView控制器

我的问题,这是正确的做法?是否有任何明确的程序/文件介绍模态视图,做与不做?

而且我现在面临的另一个问题是,当我尝试过这一点,不工作第一modalview呈现另一种模式的看法。

请说清楚。

编辑:添加的代码示例来模拟问题。 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 
+0

没有看到你的代码我必须猜测你在做什么。所以我无法帮助你。 – dasdom

回答