Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ipad UIButton addTarget不在调用选择器中_Ipad_Uibutton - Fatal编程技术网

Ipad UIButton addTarget不在调用选择器中

Ipad UIButton addTarget不在调用选择器中,ipad,uibutton,Ipad,Uibutton,让我首先声明,这不是我的选择器名称正确的问题,也不是在loadView中设置按钮目标的问题,也不是我在过去4个小时的浏览中看到的任何其他建议。我还应该解释我没有使用NIB,也没有使用IB 这些按钮在大部分开发中都起到了作用。 那就噗!不仅仅是按钮。我的表格视图不会滚动。按下表格视图中的单元格不会调用我设置的操作 看来我已经完全打破了响应者的链条;或者类似的东西。 为了试图缩小问题的根源,a创建了一个基于窗口的项目;剥离了xCode生成的所有内容;删除nib;并从我的原始应用程序委托和我的root

让我首先声明,这不是我的选择器名称正确的问题,也不是在loadView中设置按钮目标的问题,也不是我在过去4个小时的浏览中看到的任何其他建议。我还应该解释我没有使用NIB,也没有使用IB

这些按钮在大部分开发中都起到了作用。
那就噗!不仅仅是按钮。我的表格视图不会滚动。按下表格视图中的单元格不会调用我设置的操作

看来我已经完全打破了响应者的链条;或者类似的东西。
为了试图缩小问题的根源,a创建了一个基于窗口的项目;剥离了xCode生成的所有内容;删除nib;并从我的原始应用程序委托和我的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];
}

我知道这一定很简单。但我看不见。我宁愿把头发留着。我想知道在我继续学习这些怪癖的过程中,这种情况是否会发生。

是否有人打电话给
loadView
?在
loadView
中放置一个
NSLog
(或一个断点)作为健全性检查

此外,来自:

如果为了手动创建视图而重写此方法(
loadView
), 您应该这样做,并将层次结构的根视图分配给
查看
属性。(您创建的视图应该是唯一的 实例,不应与任何其他视图控制器共享 对象。)此方法的自定义实现不应调用
super

如果要对视图执行任何其他初始化,请执行以下操作 因此,在iOS 3.0及更高版本中的
viewDidLoad
方法中 还应覆盖
viewDidUnload
方法以释放任何 对视图或其内容的引用

尝试将所有按钮代码放入
viewDidLoad

- (void)buttonResponse:(id)sender {
    NSLog(@"Button touched up inside!!!!!");
}

- (void)loadView {
    // Dont call super (according to the UIViewController docs)
    // [super loadView];

    // self.view = ... however your setting up self.view 
    // self.view.frame = CGRectMake....
    // self.view.etc...
    [self.view setNeedsDisplay];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    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];

    [self.view addSubview:button];
    [self.view bringSubviewToFront:button];    
}

- (void)dealloc {
    [button release];
    [super dealloc];
}

嗨,周。谢谢你的回复。loadView实际上被称为。我发现同时定义loadView和viewDidLoad破坏了我的调用堆栈。我还尝试将loadView的内容移动到viewDidLoad,并忽略loadView。同样明显的效果…我想省略[super loadview]并为self.view分配一个框架是定义loadview的正确方法。还是没什么变化…这很奇怪。尝试输入
NSLog(@“%@,[button allControlEvents])
NSLog(@“%@,[按钮所有目标])
并查看按钮是否具有正确的操作。EXC\u BAD\u首先打开访问权限。当您将uicontrol事件作为%@传递时,第二个对象上没有触摸事件。其计算结果为64,即UIControlEventTouchUpInside。