[英]Navigating between UITextFields within UITableViewCell
在“聯系人”應用程序的添加/編輯視圖中,如果您在字段中按下“返回”鍵,則會循環瀏覽每個UITextField。 這些字段似乎在UITableViewCell中。 有什么好方法嗎?
當我的表中沒有一系列UITextField時,可以調用[self.view viewWithTag:tag]
以獲取視圖列表以及用於循環瀏覽的視圖。 但是在一個表中,我只有一個視圖,而且不確定如何將其轉換。
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
// Find the next entry field
for (UIView *view in [self entryFields]) {
if (view.tag == (textField.tag + 1)) {
[view becomeFirstResponder];
break;
}
}
return NO;
}
/*
Returns an array of all data entry fields in the view.
Fields are ordered by tag, and only fields with tag > 0 are included.
Returned fields are guaranteed to be a subclass of UIResponder.
From: http://iphoneincubator.com/blog/tag/uitextfield
*/
- (NSArray *)entryFields {
if (!entryFields) {
self.entryFields = [[NSMutableArray alloc] init];
NSInteger tag = 1;
UIView *aView;
while (aView = [self.view viewWithTag:tag]) {
if (aView && [[aView class] isSubclassOfClass:[UIResponder class]]) {
[entryFields addObject:aView];
}
tag++;
}
}
return entryFields;
}
剛剛在瀏覽自己的東西時發現了這一點-抱歉耽擱了。
如果你還沒有解決這個問題,你可以創建UITextField對象的呈現在屏幕上的順序相同的數組。 創建表時,請設置文本字段的.tag屬性。 在文本字段委托方法中-讀取標記,將其遞增1(移至下一個字段),然后發出“成為第一響應者”調用。
您還可以查看textFieldDidEndEditing委托方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.