0

I have two buttons with objects *tmpltLeft and *tmpltRight. When i launch my app, i want the previous button(tmpltLeft) initially to be hidden and when i press the next button(tmpltRight) i want the previous button(tmpltLeft) to be displayed and when the next button(tmpltRight) reaches page 20(last page) I want the next button(tmpltRight) to be hidden.

I have in .h file

IBOutlet UIButton *tmpltLeft, *tmpltRight;

In .m file

-(IBAction)templateNavigationBtnTapped:(UIButton*)sender {
UIButton *button=sender;
switch (button.tag) {
    case 1:
        NSLog(@"prev btn tapped");
        if (pageNo>1) {
            pageNo--;
        }    
        break;
    case 2:
        NSLog(@"next btn tapped");
        if (pageNo<18) {
           pageNo++;
       }
     break;
     default:
     break;
}
4

4 回答 4

2

First Set [tmpltLeft setHidden:YES]; in -viewDidLoad

 -(IBAction)templateNavigationBtnTapped:(UIButton*)sender {
    UIButton *button=sender;
    switch (button.tag) {
        case 1:
            NSLog(@"prev btn tapped");
            if (pageNo>1) {
                [tmpltRight setHidden:NO];
                pageNo--;
                if (pageNo == 1)
                {
                     [tmpltLeft setHidden:YES];
                }
            }    
            break;
        case 2:
            NSLog(@"next btn tapped");
            [tmpltLeft setHidden:NO];
            if (pageNo<18) {
               pageNo++;
               if (pageNo == 18)
               {
                    [tmpltRight setHidden:YES];
               }
           }
         break;
         default:
         break;
    }

Not Implemented , but write here to get some Idea to you...

于 2013-03-13T09:56:29.000 回答
0

You can check the page number and then hide the button. As per your code:

-(IBAction)templateNavigationBtnTapped:(UIButton*)sender {
    UIButton *button=sender;
    switch (button.tag) {
    case 1:
        NSLog(@"prev btn tapped");
        tmpltRight.hidden = NO; // for the next button in the last-1 page to be displayed if the page number is less than max number of pages. 
        if (pageNo>1) {
            pageNo--;
        } 
        else if (pageNo == 0)
           tmpltLeft.hidden = YES;
        break;
    case 2:
        NSLog(@"next btn tapped");
        tmpltLeft.hidden = NO; //for the previous button to be displayed when the page number is greater than 0.
        if (pageNo<18) {
           pageNo++;
        }
        else if (pageNo == 19)
            tmpltRight.hidden = YES;
        break;
    default:
        break;
   }

The code is not tested, but that is the general idea.

于 2013-03-13T09:56:43.130 回答
0
- (void)viewDidLoad{
    [super viewDidLoad];
    BtnCount = 0;
    previosButton.enabled = FALSE;
}
-(IBAction)previosButtonPressed:(id)sender{
    BtnCount= BtnCount-1;
    if(BtnCount==0){
        previosButton.enabled=FALSE;
    }
    if(BtnCount<19){
        nextButton.enabled= TRUE;
    }
}
-(IBAction)nextButtonPressed:(id)sender{
    previosButton.enabled = TRUE;
    BtnCount = BtnCount+1;
    if(BtnCount==19)
    {
        nextButton.enabled = FALSE;
    }   
}
于 2013-03-13T10:14:41.107 回答
0
   switch(button.tag) { case 1:
        NSLog(@"prev btn tapped");
        if (pageNo>1 || (tmpltLeft.hidden=TRUE)) {
            tmpltRight.hidden=FALSE;
            pageNo--;
            if(pageNo==1)
            tmpltLeft.hidden=TRUE;
           }
        break;
    case 2:
        NSLog(@"next btn tapped");

        if (pageNo<18 || (tmpltRight.hidden=TRUE)) {
            tmpltLeft.hidden=FALSE;
            pageNo++;
            if(pageNo==18)
                tmpltRight.hidden=TRUE;
        }
        break;
        default:
        break;
}

Initially tmpltLeft button is hidden in

  • (void)viewDidLoad {

// Template Navigation Button

tmpltLeft.hidden=TRUE;

}

于 2013-03-14T13:32:10.487 回答