2015-02-23 21 views
0

假設我有3段文本。我想用UITextView來顯示它。我有一個Next和Previous按鈕來幫助我循環。解決這個問題的最好方法是什麼?我正在嘗試一些代碼..但它不適用於我.. 實際上,我需要像這樣顯示: 如果我點擊下一個按鈕,我需要顯示像this.page of 1 of 3和page 2 of 3和page 3. 3如果單擊後退按鈕我需要顯示像3 this.page 3 3 2頁,第1頁的3如何使用ios中的next和previous UIButton在UITextView中顯示不同的文本片段

-(void)btnClicked:(UIButton*)btn 

{ 

int totalcount=3; 

if(slokaText.hidden==NO) 

{ 

if (btn.tag==1) 

{ 

NSLog(@"%lu", (unsigned long)[textStr count]); 

if (counter<[textStr count]-1) { 

counter++; 

NSLog(@"%i", counter); 

descriptionLbl1.text= [NSString stringWithFormat:@"%@", [textStr objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

} 

else 

{ 

if (counter>1) 

{ 

counter--; 

descriptionLbl1.text= [NSString stringWithFormat:@"%@", [textStr objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

}   

} 

else if (slokaMeaning.hidden==NO) 

{ 

if (btn.tag==1) 

{ 

NSLog(@"%lu", (unsigned long)[textStr1 count]); 

if (counter<[textStr1 count]-1) { 

counter++; 

NSLog(@"%i", counter); 

descriptionLbl2.text= [NSString stringWithFormat:@"%@", [textStr1 objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

} 

else 

{ 

if (counter>1) 

{ 

counter--; 

descriptionLbl2.text= [NSString stringWithFormat:@"%@", [textStr1 objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

} 

} 

else if (meaning.hidden==NO) 

{ 

if (btn.tag==1) 

{ 

NSLog(@"%lu", (unsigned long)[textStr2 count]); 

if (counter<[textStr2 count]-1) 

{ 

counter++; 

NSLog(@"%i", counter); 

descriptionLbl3.text= [NSString stringWithFormat:@"%@", [textStr2 objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

} 

else 

{ 

if (counter>1) 

{    

counter--; 

descriptionLbl3.text= [NSString stringWithFormat:@"%@", [textStr2 objectAtIndex:counter]]; 

NSLog(@"counter is :%d",counter); 

countLabel.text=[NSString stringWithFormat:@"page %d of %d",counter,totalcount]; 

} 

} 


} 

} 
+0

你遇到了什麼錯誤surya – 2015-02-23 09:15:41

+0

如果我點擊下一個按鈕顯示像這樣:第1頁3和第2頁3 ..如果我點擊返回按鈕顯示是這樣的:第2頁共3頁第1頁共3頁第0頁共3頁。 。像這樣...... – Surya 2015-02-23 10:10:34

回答

0

你可以做這樣的..

假設currentPageNumtotalPageNumyourTextView被聲明爲全局變量

- (IBAction)yourButtonAction:(UIButton *)sender 
{ 
    if (sender.tag == 1) // assumed as back action 
    { 
     if (currentPageNum > 0) 
     { 
      currentPageNum -- ; 
     } 
     else 
     { 
      currentPageNum = totalPageNum; // add this line if you want to cycle 
     } 
    } 
    else // assumed as next action 
    { 
     if (currentPageNum < totalPageNum) 
     { 
      currentPageNum ++; 
     } 
     else 
     { 
      currentPageNum = 1; // add this line if you want to cycle 

     } 
    } 

    yourTextView.text = [NSString stringWithFormat:@"Page %li of %li",(long)currentPageNum,(long)totalPageNum]; 
} 
+0

感謝您的回覆。但我有一些懷疑.. PLZ來堆棧流。我需要與你討論 – Surya 2015-02-23 07:33:26

+0

你有什麼疑問? – raki 2015-02-23 08:20:23

相關問題