在UITableview中添加UITextField基本信息
我刚刚启动了Xcode objective-c,现在我试图创建一个带有textfields的tableview来输入。我研究过其他堆栈溢出问题,但很多都是在6-8年前,似乎有广泛的答案和极其复杂的问题。有人可以帮助我了解如何在表格视图中插入文本字段并提供一些建议。谢谢!在UITableview中添加UITextField基本信息
写代码的UITableView细胞
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.delegate = self;
[aCell.contentView addSubview:txt];
ok现在就试试吧 –
你可以做到这一点,如下所示:
- 拖放到您的视图
- 拖放一个UITableView拖放一个UITableViewCell成你的桌子。
- 拖放一个UITextField(或任何其他 UI组件,你需要)
我建议你请参见教程,像
1. https://videos.raywenderlich.com/courses/22-table-views-in-ios/lessons/8 2. https://www.appcoda.com/expandable-table-view/
他们有最好的教程与所有步骤,你可以轻松地做任何你想要的。
我希望它能帮助你。
谢谢。
非常感谢,将查看教程出来 –
我已经更新了正确的教程链接。同样也适用于appcode链接。 –
非常感谢很多 –
试试下面的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
/*
* Actually create a new cell (with an identifier so that it can be dequeued).
*/
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
/*
* Now that we have a cell we can configure it to display the data corresponding to
* this row/section
*/
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(45, 30, 200, 40)];
tf.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
tf.backgroundColor=[UIColor whiteColor];
[email protected]"Hello World";
[cell.contentView addSubview:tf];
/* Now that the cell is configured we return it to the table view so that it can display it */
return cell;
}
您可以创建自定义单元格。在其中添加文本字段并通过注册笔尖或类在表中使用该文本字段。
只需通过故事板拖放uitextfield到'UITableViewCell'中即可。 – Maddy