我们正在做一个UITableViewCell
验证。该电池在点击一个textView
和一个自定义按钮,弹出了含有UIDatePickerView
应该打开&用户将选择日期。这里选择日期是强制性的。所以我们使用下面的代码进行了验证。 textViewBeginEditing
代理方法textView
位于紧接着的下一行的单元格内。即当用户点击下一行中的textView
时,以前的行值将被验证。 这里验证似乎是工作,但光标仍然闪烁在当前单元格,不移动到正在验证先前的小区。如何设置光标位置的UITextView内的UITableViewCell
UITableViewCell* myCell = (UITableViewCell*)textView.superview ;
UITextView *txtviewMycelltext;//=[[UITextView alloc]init];
for (UIView *view in myCell.subviews)
{
if([view isKindOfClass:[UILabel class]])
{
UILabel *lbl=view;
lbl.text=[lbl.text stringByReplacingOccurrencesOfString:@"." withString:@""];
int tablerowindex=[lbl.text intValue];
NSLog(@"%@",lbl.text);
break;
}
if([view isKindOfClass:[UITextView class]])
{
txtviewMycelltext=view;
}
}
inttablerowindex-=1;
if(inttablerowindex>0)
{
if([[arrActionvalues objectAtIndex:inttablerowindex1]objectForKey:KEY_FOLLOWUPDATE]==EMPTYSTRING)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Alert"
message: ALERT_FOLLOWUPDATE
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// UITableView *mytable=(UITableView *)((textView.superview).superview).superview;
UITableView *myTable=(UITableView*)[[myCell superview]superview];
NSIndexPath *indexPath = (NSIndexPath*)[myTable indexPathForCell:
(UITableViewCell*)textView.superview.superview];
UITableViewCell *previousCell = (UITableViewCell*)[myTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section]];
for (UIView *view in previousCell.subviews)
{
NSLog(@"%@",view);
if([view isKindOfClass:[UIView class]]) {
UIView *subView=view;
for(UIView *view2 in subView.subviews)
{
if([view2 isKindOfClass:[UITextView class]]) {
UITextView *txt=view2;
[txtviewMycelltext resignFirstResponder];
[txt becomeFirstResponder];
break;
}
}
}
}
}
}
请让我知道需要做什么才能将光标位置移动到正确的单元格。
这是一个情况下我会建议使用标签 –
CodaFi
究竟是什么,你确认?你的代码主要是通过视图迭代,而不是笨拙的... – Mundi
即时尝试验证用户是否选择了当前单元格中的日期。如果他没有将光标位置设置到他必须选择日期的行。 – user1531912