我一直在阅读很多东西,试图找出我做错了什么。我一直在尝试在UITableView单元格中添加4个UITextFields。我通过IB创建了UITextFields和UITableView。我将文本字段添加到NSMutableArray中,然后在cellForRowAtIndexPath中将这些文本字段对象添加到数组中的4个单元格中。然而,这就是我的问题所在。文本字段没有在表格中对齐(图片:http://cl.ly/5a02f3acdd44d8a08125)。以下是一些代码:
viewDidLoad:
viewDidLoad:
textBoxList = [[NSMutableArray alloc] init];
[textBoxList addObject: txtName];
[textBoxList addObject: txtIP];
[textBoxList addObject: txtPort];
[textBoxList addObject: txtPassword];
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cellForRowAtIndexPath是一个UITableViewDataSource协议中的方法,用于返回指定位置的单元格。在实现该方法时,我们需要根据indexPath参数来确定要返回哪个单元格,并将其作为返回值返回。
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] init] autorelease];
}
// Set up the cell...
[cell.contentView addSubview: [textBoxList objectAtIndex:[indexPath row]]];
return cell;
这是因为我在IB中设置了这些UITextFields而不是动态创建它们吗?与我的委托有关吗?我迷失了……