Search code examples
ioscocoa-touchios6uiviewuibutton

next/prev UIButtons not responding


I have a Title View defined as follows : (The Colored boxes are the frames for the respective objects)

enter image description here

LeftMost Red Box            : UIButton   : BackButton
White Box                   : UIView     : LabelsView, Contains Label 1 & Label 2
Green Box + Text            : UILabel    : Label 1
Red Box   + Text            : UILabel    : Label 2
Second White Box            : UIView     : NavigationButtonView, Contains Next And Previous Button
Two Rightmost Green Boxes   : UIButtons  : Next and Previous Button

All of the above goes into

UIView * myTitleBar;

The BackButton is working and its respective selector is being called on "Touch Up Inside" Event.

But the Next and Previous UIButtons defined as follows :

    UIButton *prevImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, navButtonWidth, navButtonHeight)];
    [prevImageButton addTarget:self action:@selector(prevImageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [prevImageButton setBackgroundColor:[UIColor greenColor]];
    
    UIButton *nextImageButton = [[UIButton alloc]initWithFrame:CGRectMake(navButtonWidth + navButtonWidth, 10, navButtonWidth, navButtonHeight)];
    [nextImageButton addTarget:self action:@selector(nextImageButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [nextImageButton setBackgroundColor:[UIColor greenColor]];

do not respond.

nextImageButtonPressed is defined as follows :

- (IBAction)nextImageButtonPressed:(id)sender{
    NSLog(@"Function Called");
    .
    .
    .
}

What might be causing this issue ? I have tried adding the buttons using

[titleBarLabelView insertSubview:navigationButtonView atIndex:1000];

Solution

  • The NavigationButtonView was being assigned as a subView of LabelsView instead of myTitleBar. So even though it was visible, the user cannot interact with it, as it is being clipped.