首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在UITableview中添加UITextField基础知识

在UITableview中添加UITextField基础知识
EN

Stack Overflow用户
提问于 2017-06-29 18:05:10
回答 4查看 82关注 0票数 0

我最近刚开始使用Xcode objective-c,现在我正在尝试创建一个包含文本字段的表视图来进行输入。我已经研究了其他堆栈溢出问题,但许多都是6-8年前的问题,似乎有各种各样的答案,而且非常复杂。谁可以帮助我如何在表视图中插入文本字段的基础知识,并给我一些建议。谢谢!

EN

回答 4

Stack Overflow用户

发布于 2017-06-29 18:15:57

在uitableview单元格中编写此代码

代码语言:javascript
运行
复制
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
textField.clearsOnBeginEditing = NO;
textField.textAlignment = UITextAlignmentRight;
textField.delegate = self;  
[aCell.contentView addSubview:txt];
票数 1
EN

Stack Overflow用户

发布于 2017-06-29 18:21:28

您可以执行以下操作:

  1. 将UITableView拖放到视图中
  2. 将UITableViewCell拖放到表中。
  3. 拖放UITextField (或所需的任何其他UI组件)

我建议您参考类似的教程。

1.https://videos.raywenderlich.com/courses/22-table-views-in-ios/lessons/8 2.https://www.appcoda.com/expandable-table-view/

他们有最好的教程,所有的步骤你可以很容易地做任何你想做的事情。

我希望它能对你有所帮助。

谢谢。

票数 1
EN

Stack Overflow用户

发布于 2017-06-29 18:27:49

尝试下面的代码

代码语言:javascript
运行
复制
- (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;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44822108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档