【发布时间】:2011-10-30 04:08:43
【问题描述】:
首先让我声明,这不是让我的选择器名称正确的问题,也不是在 loadView 中设置按钮目标的问题,也不是我在过去 4 小时的浏览中看到的任何其他建议。我还应该解释一下我没有使用笔尖,也没有使用 IB。
这些按钮已用于大部分开发。
然后噗!不仅仅是按钮。我的表格视图不滚动。按下表格视图中的单元格不会调用我设置的操作。
看来我已经完全破坏了响应者链;或类似的东西。
为了尝试缩小问题的根源,创建了一个基于窗口的项目;剥离 xCode 生成的所有内容;删除了笔尖;并从我的原始应用程序委托和我的 rootViewController 中复制了几种方法。
这是包含按钮的子视图的 RVT。非常坦率的。一样的效果。我已经从字面上剥离了所有功能代码,但 appDelegate.m 中的以下源代码:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setDelegate:self];
if(window == nil)
window = [[UIWindow alloc] init];
window.autoresizesSubviews = YES;
if(controller == nil)
controller = [[Controller alloc] init];
window.rootViewController = controller;
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[window release];
[controller release];
[super dealloc];
}
在控制器中:
- (void)buttonResponse {
NSLog(@"Button touched up inside!!!!!");
}
- (void)loadView {
[super loadView];
//test
button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Button" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
CGSize imageSize = [image size];
CGRect buttonFrame = CGRectMake(0,0,imageSize.width + 100, BUTTONBAR_H + 100);
button.frame = buttonFrame;
[button setImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"" forState:UIControlStateNormal];
button.userInteractionEnabled = YES;
[button addTarget:self action:@selector(buttonResponse) forControlEvents: UIControlEventTouchUpInside];
UIView *view = self.view;
CGRect viewFrame = view.frame; //self.view is valid and takes up available screen
[self.view addSubview:button];
[self.view bringSubviewToFront:button];
//end test
[self.view setNeedsDisplay];
}
- (void)dealloc {
[button release];
[super dealloc];
}
我知道这一定很简单。但我看不到它。我宁愿把头发留在原处。我想知道随着我继续学习这些怪癖,这是否会发生。
【问题讨论】: