iphone - UITableView 单元格内的 UITextField

标签 iphone uitableview ios uitextfield

我一直在阅读很多东西,试图找出我做错了什么。我一直在尝试在 UITableView 单元格中添加 4 个 UITextFields。我有通过 IB 创建的 UITextFields 以及 UITableView。我将文本字段添加到 NSMutableArray,然后在 cellForRowAtIndexPath 中我将这些文本字段对象添加到数组中。分成 4 个单元格。但是,这就是我的问题出现的地方。文本字段未在表中排列(img:http://cl.ly/5a02f3acdd44d8a08125)。这是一些代码:

viewDidLoad: textBoxList = [[NSMutableArray alloc] init];

[textBoxList addObject: txtName];
[文本框列表添加对象:txtIP];
[文本框列表添加对象:txtPort];
[文本框列表添加对象:txt密码];

cellForRowAtIndexPath: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(细胞==无){
    cell = [[[UITableViewCell alloc] init] autorelease];
}

//设置单元格...
[cell.contentView addSubview: [textBoxList objectAtIndex:[indexPath row]]];


返回单元格;

}

发生这种情况是因为我在 IB 中设置了这些 UITextFields 而不是动态创建它们吗?我的代表有事吗?我迷路了....

最佳答案

您需要设置标签相对于单元格的框架。

关于iphone - UITableView 单元格内的 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4030169/

相关文章:

ios - Swift Combine compactMap 不起作用(Xcode 13)

iphone - 如何在 UITapGestureRecognizer 中的 @selector 中传递参数?

ios - 奇怪的 UITableView 错误

ios - 自定义 UICollectionViewFlowLayout 问题

ios - 在 applicationDidEnterBackground 期间无法暂停音频

ios - 如何在 iOS 中检查文本是否被选中以及十字按钮是否被按下?

iphone - UIButton 在 InterfaceBuilder 中看起来不错,但在 iPad sim 或设备上则不然

iphone - Paypal 自适应支付移动浏览器(iPhone 上的 Safari 和 Chrome)

iphone - iOS:应用程序图标角标(Badge)不会消失

ios - Swift 在每个部分中选择一个单元格