【发布时间】:2011-06-24 13:49:57
【问题描述】:
好的,请耐心等待:由于这是一个与 Objective-C 相关的问题,显然有很多代码和子类化。所以这是我的问题。现在,我有一个 iPad 应用程序,它以编程方式创建一个按钮和两个彩色 UIView。这些彩色的 UIView 是由 SubViewControllers 控制的,整个东西都在一个由 MainViewController 控制的 UIView 中。 (即 MainViewController = [UIButton, SubViewController, SubViewController])
现在,所有这一切都发生了,我最终得到了我所期望的结果(如下):
但是,当我单击按钮时,控制台显示“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:模态视图不起作用。应该看到翻转。不要。
【问题讨论】:
-
你在哪里设置 theView 为 SubViewController 的视图?
标签: objective-c ios view controller modal-dialog