Issue with button on the left side of the uinavigation bar

后端 未结 3 640
野的像风
野的像风 2021-01-03 11:32

I have a button on the left side of the navigation bar. I also have a UIButton near that button.

Now when I click the button thats below the navigation bar, in many

3条回答
  •  失恋的感觉
    2021-01-03 12:13

    It looks like a problem with how you're initializing the UIButton instance. Typically, we would use [UIButton buttonWithType:custom]; in your situation.

    From this answer, they solved a similar question with the following:

    UIImage *myImage = [UIImage imageNamed:@"paw.png"];
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [myButton setImage:myImage forState:UIControlStateNormal];
    myButton.showsTouchWhenHighlighted = YES;
    myButton.frame = CGRectMake(0.0, 0.0, myImage.size.width, myImage.size.height);
    
    [myButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    [rightButton release];
    [myButton release];
    

    It's not the code you're looking for, but it shows you how to correctly instantiate a UIButton instance. Hopefully that will sort out the problems you're having.

提交回复
热议问题