Welcome, Guest
Username Password: Remember me

Previous TextField & Next TextField
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Previous TextField & Next TextField

Previous TextField & Next TextField 1 year, 7 months ago #1

Hi,

I have a table view set up by SCTableViewModel. This table view has SCTextField's, SCTextView's and some other type of cells. What I need to do is, when the user taps a button at the top of the keyboard I want the user to be able to go to the next TextField or TextView to edit them, if possible without ever closing the keyboard. I have tried anything I can think of to do this but I'm not able to. I don't know if there is method for this in the Sensible Coca. I hope there is. Thanks in advance.

These are the methods I'm trying to fill:

 
- (IBAction) previousAction:(id) sender {
 
}
 
- (IBAction) nextAction:(id) sender {
 
}
 


Best Regards,

Oguz
  • leweo
  • OFFLINE
  • Junior Boarder
  • Posts: 24
  • Karma: 0

Re: Previous TextField & Next TextField 1 year, 7 months ago #2

Sensible TableView will automatically move you to the next editable field when you tap the Return/Next button on the keyboard. Are you having any problems with that? As for creating a "Prev" button, it's currently on our requested features list.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Previous TextField & Next TextField 1 year, 7 months ago #3

No, the return key works fine. My company wanted me to create a bar like in the safari application, 3 buttons in it. Prev, next and done. I created the bar, everything is fine, but my textfields are in the tableview, so I need to go to the prev and next textfields in the tableview =S
  • leweo
  • OFFLINE
  • Junior Boarder
  • Posts: 24
  • Karma: 0

Re: Previous TextField & Next TextField 1 year, 7 months ago #4

When your custom button is tapped, you can advance using pretty much the same code SCTextFieldCell uses (please check out the "textFieldShouldReturn" method in SCTextFieldCell).
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Previous TextField & Next TextField 1 year, 6 months ago #5

Thanks for your help. I managed to solve the problem. Here is how:
 
- (IBAction) previousAction:(id) sender {
NSIndexPath *indexPath = [tableViewModel indexPathForCell:tableViewModel.activeCell];
if(indexPath.row == 0) {
return;
}
else {
int temp = indexPath.row - 1;
 
NSIndexPath *newPath = [NSIndexPath indexPathForRow:temp inSection:0];
if(temp != 8) {
[tableView scrollToRowAtIndexPath:[tableViewModel indexPathForCell:[tableViewModel cellAfterCell:[tableViewModel cellAtIndexPath:newPath] rewindIfLastCell:YES]]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
[tableViewModel.activeCell resignFirstResponder];
[[tableViewModel cellAtIndexPath:newPath] becomeFirstResponder];
}
}
 
- (IBAction) nextAction:(id) sender {
SCTableViewCell *currentCell = tableViewModel.activeCell;
SCTableViewCell *nextCell;
while( (nextCell = [tableViewModel cellAfterCell:currentCell rewindIfLastCell:NO]) )
{
if([nextCell isKindOfClass:[SCTextFieldCell class]] || [nextCell isKindOfClass:[SCTextViewCell class]]) {
break;
}
else
{
nextCell = nil;
break;
}
}
 
if(nextCell)
{
[currentCell resignFirstResponder];
[nextCell becomeFirstResponder];
}
else {
[currentCell resignFirstResponder];
}
}
 


It may help someone. Thanks again =)
  • leweo
  • OFFLINE
  • Junior Boarder
  • Posts: 24
  • Karma: 0

Re: Previous TextField & Next TextField 1 year, 6 months ago #6

Thanks a lot Oguz for posting this
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
  • Page:
  • 1
Time to create page: 2.78 seconds