【发布时间】:2009-10-26 00:05:56
【问题描述】:
我使用 File/New Projet/View-Based 应用程序创建了一个非常基本的 iPhone 应用程序。 那里没有 NIB 文件。
这是我的 appDelegate
.h
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MyViewController *viewController;
}
.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
这是我控制器中的 loadView 方法
- (void)loadView {
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:mainFrame];
contentView.backgroundColor = [UIColor redColor];
self.view = contentView;
[contentView release];
}
现在,为了捕捉 touchesBegan 事件,我创建了一个新的 UIView 子类:
.h
@interface TouchView : UIView {
}
.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touch detected");
}
并将我的 loadView 中的第二行修改为:
TouchView *contentView = [[UIView alloc] initWithFrame:mainFrame];
为什么从不调用 touchesBegan?
【问题讨论】:
标签: iphone-sdk-3.0 uiview uiviewcontroller