开发者

iphone keyboard won't appear

开发者 https://www.devze.com 2022-12-24 09:39 出处:网络
I can click on the field, and it momentarily turns blue, but those events plus makeFirstResponder together do not cause the keyboard to show on a UITextField.

I can click on the field, and it momentarily turns blue, but those events plus makeFirstResponder together do not cause the keyboard to show on a UITextField.

Plain vanilla code follows; I include it so others can discern what is NOT there and therefore what, presumably, with solve the problem.

I put in leading spaces to format this question more like code, but the parser seems to have stripped them, thus leaving left-justified code. Sorry!

UITextFieldDelete, check:

@interface RevenueViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {

UILabel *sgmntdControlLabel; UISegmentedControl *sgmntdControl; UITableView *theTableView; }

@property(nonatomic,retain) UISegmentedControl *sgmntdControl;
@property(nonatomic,retain) UILabel *sgmntdControlLabel;

Delegate and source, check.

-(void)loadView;
  // code
  C开发者_如何转开发GRect frameTable = CGRectMake(10,0,300,260);
  theTableView = [[UITableView alloc] initWithFrame:frameTable style:UITableViewStyleGrouped];
  [theTableView setDelegate:self];
  [theTableView setDataSource:self];
  // code
  [self.view addSubview:theTableView];
  [super viewDidLoad];
}

Insert UITextField to cell, check.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger sectionNmbr = [indexPath section];
NSInteger rowNmbr = [indexPath row];
NSLog(@"cellForRowAtIndexPath=%d, %d",sectionNmbr,rowNmbr);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell. 
switch (sectionNmbr) {
case 0: 
   if (rowNmbr == 0) {
   cell.tag = 1;
   cell.textLabel.text = @"Label for sctn 0, row 0";
   UITextField *tf = [[UITextField alloc] init];
   tf.keyboardType = UIKeyboardTypeNumberPad;
   tf.returnKeyType = UIReturnKeyDone;
   tf.delegate = self;
   [cell.contentView addSubview:tf];
  }
if (rowNmbr == 1) {
cell.tag = 2;
cell.textLabel.text = @"Label for sctn 0, row 1";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

} break; } }

Successfully end up where we want to be (?), no check, (and no keyboard!):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"didSelectRowAtIndexPath");
switch (indexPath.section) {
case 0: 
NSLog(@"  section=0, rowNmbr=%d",indexPath.row);
switch (indexPath.row) {
case 0:
UITableViewCell *cellSelected = [tableView cellForRowAtIndexPath: indexPath];
UITextField *textField = [[cellSelected.contentView subviews] objectAtIndex: 0];
[ textField setEnabled: YES ];
[textField becomeFirstResponder];
// here is where keyboard will appear?
[tableView deselectRowAtIndexPath: indexPath animated: NO];
break;
case 1:
// code
break;
default:
break;

} break; case 1: // code break; default: // handle otherwise un-handled exception break; } }

Thank you for your insights!


are you sure that

[[cellSelected.contentView subviews] objectAtIndex: 0];

is returning what you expect it to? Try checking it with the debugger

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号