-2

我有 2 个 IBaction 来增加或减少页码,但我希望我的页码永远不会为 0 或小于 0

-(IBAction)pageNumberPlus1:(id)sender {
labelpageNumberButton.text = [NSString stringWithFormat:@"%d",[labelpageNumberButton.text intValue]+1];}

   -(IBAction)pageNumberMoins1:(id)sender {
   labelpageNumberButton.text = [NSString stringWithFormat:@"%d",[labelpageNumberButton.text intValue]-1];
if (labelpageNumberButton.text <= [NSString stringWithFormat:@"%d",0])  {
    labelpageNumberButton.text = [NSString stringWithFormat:@"%d",1];}}

这段代码在减少时很糟糕,它给出了不好的价值

4

1 回答 1

0

工作正常:

-(IBAction)pageNumberPlus1:(id)sender { 
self.pageNumber++; 
labelpageNumber.text = [NSString stringWithFormat:@"%d",_pageNumber]; } 

-(IBAction)pageNumberMoins1:(id)sender { 
self.pageNumber--; 
if(_pageNumber <= 0) _pageNumber = 1; labelpageNumber.text = [NSString stringWithFormat:@"%d",_pageNumber]; }
于 2013-05-04T03:26:54.250 回答