Welcome, Guest
Username Password: Remember me

textField resignFirstResponder
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: textField resignFirstResponder

textField resignFirstResponder 1 year, 2 months ago #1

Hi,

I'm testing a SCControlCell with this simple settings:

 
- (void)viewDidLoad
{
[super viewDidLoad];
 
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStyleBordered target:self action:@selector(send:)];
 
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel:)];
 
self.navigationItem.rightBarButtonItem = sendButton;
self.navigationItem.leftBarButtonItem = cancelButton;
self.navigationItem.title = @"Test";
 
tableModel = [[SCTableViewModel alloc] initWithTableView:self.tableView withViewController:self];
 
SCTableViewSection *sectionOne = [SCTableViewSection sectionWithHeaderTitle:@"Section 1"];
[tableModel addSection:sectionOne];
 
//Section 1 Data
NSDictionary *sectionOneDataBindings = [NSDictionary
dictionaryWithObjects:[NSArray arrayWithObjects:@"a", @"b", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]]; // 1,2 are the control tags
 
SCControlCell *sectionOneDataCell = [SCControlCell cellWithText:nil withKeyBindings:sectionOneDataBindings withNibName:@"TestCell"];
[sectionOne addCell:sectionOneDataCell];
 
}
 
 


I need to resignFirstResponder if the user press the send button while is editing a textField in order to dismiss the keyboard. I've tried with this code but it doesn't work

 
 
- (IBAction)send:(id)sender {
NSLog(@"Send Pressed");
 
SCTableViewCell *currentCell = tableModel.activeCell;
if ([currentCell isKindOfClass:[SCTextFieldCell class]]) {
[currentCell resignFirstResponder];
}
 
}
 


Any help would be appreciated.

Best Regards,

Enric
  • lostinbcn
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 4

Re: textField resignFirstResponder 1 year, 2 months ago #2

Hi Enric,

Assuming the "send:" method does get called, what's the value for tableModel.activeCell when you step into the method?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: textField resignFirstResponder 1 year, 2 months ago #3

I'm sorry Tarek. I don't understand "what's the value for tableModel.activeCell"

Apologies
  • lostinbcn
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 4

Re: textField resignFirstResponder 1 year, 2 months ago #4

Apologies for not being clear Enric:

 
- (IBAction)send:(id)sender {
NSLog(@"Send Pressed");
 
NSLog(@"tableModel.activeCell = %@", tableModel.activeCell);
 
SCTableViewCell *currentCell = tableModel.activeCell;
if ([currentCell isKindOfClass:[SCTextFieldCell class]]) {
[currentCell resignFirstResponder];
}
 
}
 


What's the value given by the above NSLog? Also, please feel free to send me the project (at our support email) to take a look at.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: textField resignFirstResponder 1 year, 2 months ago #5

Thanks Tarek for you support.

This is the NSLog output.


2011-03-15 19:11:54.215 pruebas_SCTableView[9749:207] tableModel.activeCell = <SCControlCell: 0x4c30660; baseClass = UITableViewCell; frame = (0 46; 320 133); autoresize = W; layer = <CALayer: 0x4c30890>>


If I understand this output, the active cell is SCControlCell then, the method
 
SCTableViewCell *currentCell = tableModel.activeCell;
if ([currentCell isKindOfClass:[SCTextFieldCell class]]) {
[currentCell resignFirstResponder];
}
 


would not work.

Please say me which is your email support in order to send you this project.

Thanks in advance.

Enric
  • lostinbcn
  • OFFLINE
  • Junior Boarder
  • Posts: 22
  • Karma: 4
Last Edit: 1 year, 2 months ago by lostinbcn. Reason: typo error

Re: textField resignFirstResponder 1 year, 2 months ago #6

Yes Enric, I was just making sure that the method is properly being called. As you see, the active cell is your SCCustomCell. Your code should look something like this:

 
- (IBAction)send:(id)sender {
 
SCTableViewCell *currentCell = tableModel.activeCell;
if ([currentCell isKindOfClass:[SCControlCell class]]) {
//you can do the following in a loop if you wish
[[currentCell controlWithTag:1] resignFirstResponder];
[[currentCell controlWithTag:2] resignFirstResponder];
}
}
 


Please tell me if this works well for you.

I also think we should modify SCControlCell's resignResponder method to automatically resign the keyboard for any of its sub-controls, so that you won't have to do this yourself. I'll make sure to include this in our final STV 2.0 release. Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 2 months ago by tarekskr.
  • Page:
  • 1
  • 2
Time to create page: 2.06 seconds