小编Teo*_*dor的帖子

UIButton addTarget:action:forControlEvents:[NSObject doesNotRecognizeSelector:]中的结果

我尝试了很多东西,但仍然没有结果.

所以我在UIViewController的子类中以编程方式创建了以下按钮:

    rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0.0, 0.0, 110.0, 40.0);
    rightButton.titleLabel.font = [UIFont fontWithName:GAME_FONT_NAME_STRING size:20.0];
    [rightButton setTitle:@"MyTitle" forState:UIControlStateNormal];
    rightButton.backgroundColor = [UIColor clearColor];
    [rightButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    [rightButton setBackgroundImage:normalImage forState:UIControlStateNormal];
    [rightButton setBackgroundImage:highlightedImage forState:UIControlStateHighlighted];
    [rightButton addTarget:self action:@selector(myButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightButton];
Run Code Online (Sandbox Code Playgroud)

选择器在哪里:

- (void)myButton;
Run Code Online (Sandbox Code Playgroud)

我尝试了一切:

- (void)myButton;
- (void)myButton:(id)sender;
- (void)myButton:(id)sender forEvent:(UIEvent *)event;
- (IBAction)myButton;
- (IBAction)myButton:(id)sender;
- (IBAction)myButton:(id)sender forEvent:(UIEvent *)event;
Run Code Online (Sandbox Code Playgroud)

和相应的选择器,当然:

[rightButton addTarget:self action:@selector(myButton) forControlEvents:UIControlEventTouchUpInside];
[rightButton addTarget:self action:@selector(myButton:) forControlEvents:UIControlEventTouchUpInside];
[rightButton addTarget:self action:@selector(myButton:forEvent:) forControlEvents:UIControlEventTouchUpInside];
[rightButton addTarget:self action:@selector(myButton) …
Run Code Online (Sandbox Code Playgroud)

iphone uibutton uicontrol uncaught-exception

5
推荐指数
2
解决办法
6万
查看次数

标签 统计

iphone ×1

uibutton ×1

uicontrol ×1

uncaught-exception ×1