0

I hope I can ask this question clearly, I have a viewController that I build programmatically (not with NIB), this view controller has two buttons I draw on the lower portion of the view

"prev" and "next" what I'd like to do is, when I've reached the "end" I'd like to only draw the "prev" button, and not the "next", and vice-versa, when I'm at the beginning, I'd like to only draw the "next" and not the prev.

Any general ideas on how to approach this ?

Thanks,

uba

4

2 回答 2

1

You can use "hidden" property of UIButton:

if (page == firstPage) {
    self.myButtonPrev.hidden = YES;
} else {
    self.myButtonPrev.hidden = NO;
}

if (page == lastPage) {
    self.myButtonNext.hidden = YES;
} else {
    self.myButtonNext.hidden = NO;
}
于 2012-08-23T00:03:08.933 回答
1

The first thing to do is to addTarget for your button to listen to touch events

[yourButtonNameHere addTarget:self action:@selector(yourCallBackFunctionNameHere:) forControlEvents:UIControlEventTouchUpInside];

What this does is whenever your button is pressed it calls the yourCallBackFunctionNameHere function. Do this for the other button too. The semi colon after the function indicates that the function has to send the information of the UIElement that caused the event to occur.

Assign tags to both the buttons.

youButtonNameHere.tag=yourTag;

In the function check which button is sending the UIcontrolEvent by comparing the tags

- (void)yourFunctionNameHere:(id)sender {
   UIButton *yourButton =(UIButton *)sender;

    if(yourButton.tag==501){

      // logic to check if this is the first or last page and act accordingly
       yourButton.hidden = YES / NO based on what you want to do.
     }else{  
     // logic to do otherwise.
     }
于 2012-08-23T00:03:49.680 回答