0
在我的應用程序中,如果快速點擊「下一步」按鈕(返回鍵),會導致問題。有沒有辦法阻止用戶這樣做?我自己無法想到一個解決方案。iPhone鍵盤快速點擊「下一步」按鈕
我在一個UIScrollView與許多頁面,並在某個頁面上我有一個鍵盤彈出,所以用戶可以鍵入到一個UITextField。點擊下一個按鈕會提示滾動視圖滑動到下一頁。但是,如果用戶點擊按鈕太多,會導致滾動視圖跳轉。
下面的代碼是當返回鍵被竊聽,關鍵的部分是它調用[self setPage:6];
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
//Enter your first and last name
if (textField == firstnameField1)
{
//Put the text into a string to be saved
firstName1 = firstnameField1.text;
//Send user to next field (your surname)
[surnameField1 becomeFirstResponder];
}
else if (textField == surnameField1)
{
//Put text into a string to be saved
surname1 = surnameField1.text;
//Move to the next stage, enter partners name
if (pageController.currentPage == 4) {
[self setPage:5];
}
else if (pageController.currentPage == 3)
{
[self setPage:5];
}
currentStage = stage6;
}
//Enter your partners first and last name
if (textField == firstnameField2)
{
//Put the text into a string to be saved
firstName2 = firstnameField2.text;
//Send user to next field (your partners surname)
[surnameField2 becomeFirstResponder];
}
else if (textField == surnameField2)
{
//Put text into a string to be saved
surname2 = surnameField2.text;
//Move to the next stage, enter partners name
if (pageController.currentPage == 5) {
[self setPage:6];
}
else if (pageController.currentPage == 4)
{
[self setPage:6];
}
currentStage = stage7;
}
return YES;
}
這種方法setPage
低於:
-(void)setPage:(int)destinationPage
{
//Scroll to appropriate page in scroll view
CGRect frame = scrollViewController.frame;
frame.origin.x = frame.size.width * destinationPage;
frame.origin.y = 0;
[scrollViewController scrollRectToVisible:frame animated:YES];
}
感謝。
「它導致問題」可以是任何事情 - 更詳細地描述您的問題! – JonasG 2012-01-10 21:08:14
它會導致什麼問題? – 2012-01-10 21:08:15
添加了代碼示例,對於之前缺乏細節感到抱歉。 – 2012-01-10 21:34:11