【发布时间】:2016-01-30 17:10:36
【问题描述】:
我从 Aaron Hillegass 的一本书开始学习 iOS 编程,但我发现有些示例不起作用。也许它们不起作用,因为有新版本的 iOS 和 Xcode。你能解释一下为什么这段代码不起作用吗?正在创建按钮;但是,它没有收到新闻。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(10,50,100,10)];
[button setTitle:@"OK" forState:UIControlStateNormal];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:button];
[self.window makeKeyAndVisible];
return YES;
}
对此类问题的流行建议是添加
button.userInteractionEnabled = YES;
但没用。
对不起,如果我的问题很简单,但我花了几个小时在这里和 developer.apple.com 上找到答案。
【问题讨论】:
-
按钮是否出现了?
-
是的,我可以看到但不能按下它
-
添加目标操作应该可以工作
-
不幸的是没有
标签: ios objective-c addsubview