2010-10-27 49 views
4

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

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 {

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并不能动态地创建他们?与我的代表有什么关系? Im lost ....

回答

3

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

+0

是否这样? \t txtName = [[UITextField alloc] initWithFrame:CGRectMake(0,0,100,30)]; \t txtIP = [[UITextField alloc] initWithFrame:CGRectMake(0,0,100,30)]; \t txtPassword = [[UITextField alloc] initWithFrame:CGRectMake(0,0,100,30)]; \t txtPort = [[UITextField alloc] initWithFrame:CGRectMake(0,0,100,30)]; – bmilleker 2010-10-27 23:10:10

+0

那么,如果您已经将它们放入装入的笔尖中,则不需要创建所有新标签。除非你正在摆脱这种策略? – 2010-10-27 23:42:56

+0

我仍在使用该策略。不知道如何设置他们的框架虽然 – bmilleker 2010-10-27 23:47:57