We are doing a validation in a UITableViewCell. The cell has a textView and a custom button on clicking which a pop over containing a UIDatePickerView should open & the user will select the date. Here selecting the date is mandatory. So we did a validation using the below code. In the textViewBeginEditing delegate method of the textView inside the cell in the immediate next row. i.e when the user clicks on the textView in the next row the previous row values will be validated.
Here the validation seems to be working but the cursor still blinks in current cell and do not move to the previous cell that is being validated.
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;
}
}
}
}
}
}
Please let me know what needs to be done to get the cursor position to the correct cell.
It is not very clear from you code, but, I am guessing you are performing your validations inside
textViewDidEndEditing.textViewShouldEndEditingis the appropriate delegate method to perform validation of the text view contents. You can return NO if you want to prevent the switching of focus from the current text view.http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intfm/UITextViewDelegate/textViewShouldEndEditing: