0
我可以點擊該字段,它暫時變成藍色,但這些事件加上makeFirstResponder在一起不會導致鍵盤顯示在UITextField上。iphone鍵盤不會出現
普通香草代碼如下;我把它包括在內,以便其他人可以辨別什麼是不存在的,因此可以解決問題。
我把領先的空格作爲代碼進行格式化,但解析器似乎已經剝離了它們,因此留下了左對齊的代碼。抱歉!
UITextFieldDelete,檢查:
@interface RevenueViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {
的UILabel * sgmntdControlLabel; UISegmentedControl * sgmntdControl; UITableView * theTableView; }
@property(nonatomic,retain) UISegmentedControl *sgmntdControl;
@property(nonatomic,retain) UILabel *sgmntdControlLabel;
委託和來源,檢查。
-(void)loadView;
// code
CGRect 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];
}
插入UITextField到單元格,檢查。
- (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; }}
成功結束了,我們想要的,沒有檢查,:
- (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;
} 休息;(?)(且沒有鍵盤!) 案例1: //代碼 break; 默認值: //處理其他未處理的異常 break; } }
謝謝你的見解!