好的,請耐心等待:因爲這是Objective-C相關的問題,顯然有很多代碼和子類。所以這是我的問題。現在,我有一個iPad應用程序,它以編程方式創建一個按鈕和兩個彩色的UIViews。這些彩色的UIViews是由SubViewControllers控制的,整個事物都在一個由MainViewController控制的UIView中。 (即MainViewController = [UIButton的,SubViewController,SubViewController])現在ModalViewController for Single Subview
,這一切發生,因爲它應該和我結束了我所期望的(如下圖):
然而,當我點擊按鈕,控制檯顯示「flipSubView1」,沒有任何反應。沒有顯示模態視圖,也沒有發生錯誤。根本不值一提。我期望的是subView1或整個視圖將水平翻轉並顯示subView3。是否有一些我錯過的代碼會導致這種情況發生/是否有一些我忽略的錯誤?
viewtoolsAppDelegate.m
@implementation viewtoolsAppDelegate
@synthesize window = _window;
@synthesize mvc;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mvc = [[MainViewController alloc] initWithFrame:self.window.frame];
[self.window addSubview:mvc.theView];
[self.window makeKeyAndVisible];
return YES;
}
MainViewController.m
@implementation MainViewController
@synthesize theView;
@synthesize subView1, subView2, subView3;
- (id)initWithFrame:(CGRect) frame
{
theView = [[UIView alloc] initWithFrame:frame];
CGRect sV1Rect = CGRectMake(frame.origin.x+44, frame.origin.y, frame.size.width-44, frame.size.height/2);
CGRect sV2Rect = CGRectMake(frame.origin.x+44, frame.origin.y+frame.size.height/2, frame.size.width-44, frame.size.height/2);
subView1 = [[SubViewController alloc] initWithFrame:sV1Rect andColor:[UIColor blueColor]];
subView2 = [[SubViewController alloc] initWithFrame:sV2Rect andColor:[UIColor greenColor]];
subView3 = [[SubViewController alloc] initWithFrame:sV1Rect andColor:[UIColor redColor]];
[theView addSubview:subView1.theView];
[theView addSubview:subView2.theView];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aButton addTarget:self action:@selector(flipSubView1:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[aButton setFrame:CGRectMake(0, 0, 44, frame.size.height)];
[theView addSubview:aButton];
return self;
}
- (void)flipSubView1:(id) sender
{
NSLog(@"flipSubView1");
[subView3 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[subView1 presentModalViewController:subView3 animated:YES];
}
SubViewController.m
@implementation SubViewController
@synthesize theView;
- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color
{
theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = color;
return self;
}
TLDR:不工作模式的看法。應該看到翻轉。別。
你在哪裏設置視圖爲SubViewController的視圖? – thomashw