我最近刚开始使用Xcode objective-c,现在我正在尝试创建一个包含文本字段的表视图来进行输入。我已经研究了其他堆栈溢出问题,但许多都是6-8年前的问题,似乎有各种各样的答案,而且非常复杂。谁可以帮助我如何在表视图中插入文本字段的基础知识,并给我一些建议。谢谢!
发布于 2017-06-29 18:15:57
在uitableview单元格中编写此代码
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.delegate = self;
[aCell.contentView addSubview:txt];发布于 2017-06-29 18:21:28
您可以执行以下操作:
我建议您参考类似的教程。
1.https://videos.raywenderlich.com/courses/22-table-views-in-ios/lessons/8 2.https://www.appcoda.com/expandable-table-view/
他们有最好的教程,所有的步骤你可以很容易地做任何你想做的事情。
我希望它能对你有所帮助。
谢谢。
发布于 2017-06-29 18:27:49
尝试下面的代码
- (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];
tf.text=@"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;
}https://stackoverflow.com/questions/44822108
复制相似问题