2012-08-30 35 views
0

所以我正在尋找一種方法來在我的iPhone中創建某種形式。我添加例如3個文本框,當我點擊第一個文本框並寫入內容時,我希望能夠按下一個文本框,然後將我帶到下一個文本框。如何啓用簡單形式的next和prev按鈕

鏈接:http://shrani.si/f/3U/lB/3Nl9qXha/primer.png

我想要做的事,如果你在Web表格等。

+0

也許你找到一個SOLUT離子關於或使用這個開源軟件http://escoz.com/open-source/quickdialog – lukaswelte

回答

1

當用戶點擊下一步,就可以使用,

[nextTextFieldAlong becomeFirstResponder]; 

...將光標移動到下一個字段。

+0

那麼我的鍵盤沒有按鈕,但我想知道如何添加它...那麼prev呢? – gabrjan

+0

無論您想要移到哪一個控制項(無論是上一個還是下一個控制項),都會調用becomeFirstResponder。 [textFieldToMoveTo becomeFirstResponder]; – Snips

+0

好吧,但我有添加這些按鈕鍵盤? – gabrjan

1

首先,你必須設置標籤爲您的域(1-3),然後設置一個accsesory鑑於您的文本框這樣

[messageView setInputAccessoryView:[self createAccesoryView]]; 

可以使用的方法是這樣產生的accesory視圖(這是從蘋果的文件需要):

-(UIView*)createAccesoryView{ 
     UIToolbar *toolbar = [[[UIToolbar alloc] init] autorelease]; 
     [toolbar setBarStyle:UIBarStyleDefault]; 
     [toolbar sizeToFit]; 
     UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Previous", @"Next", nil]]; 
     [segmentControl setSegmentedControlStyle:UISegmentedControlStyleBar]; 
     [segmentControl addTarget:self action:@selector(selectNextPrevious:) forControlEvents:UIControlEventValueChanged]; 
     UIBarButtonItem *select = [[UIBarButtonItem alloc] initWithCustomView:segmentControl]; 
     UIBarButtonItem *flex = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
     UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneTyping)]; 
     [toolbar setItems:[NSArray arrayWithObjects:select, flex, done, nil]]; 
     return toolbar; 
    } 

然後在selectNextPrevious

-(void)selectNextPrevious:(id)sender{ 
if ([(UISegmentedControl*)sender selectedSegmentIndex]==0) { 
if (activeField.tag>1) { 
      [[self.view viewWithTag:activeField.tag-1] becomeFirstResponder]; 
     } 
else { 
     if (activeField.tag<numberOfFields) { 
      [[self.view viewWithTag:activeField.tag+1] becomeFirstResponder]; 
     } 
    } 

} 
+0

這聽起來很不幸,我今天沒有時間去測試它。我明天告訴你它是如何結束的。 – gabrjan

+0

嗨,再次我測試的代碼,但它不工作,因爲我不知道什麼是第一行代碼messageView ... – gabrjan

+0

我想這一切,我jsut DN /噸知道如何確定哪個字段是當時處於活動狀態... – gabrjan

相關問題