iOS7 中 UITextField 中的设置器不起作用,但在 iOS6 中有效


    -(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    ...
    for (int i = 0; i < 6; i++) {
        VVUserInformationCell *cell = (VVUserInformationCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        NSLog(@"%@", array[i][1]);
        [cell.userData setText: array[i][1]];
        [cell.userData setTag:i];
        NSLog(@"%@", cell.userData.text);
        NSLog(@"%d", cell.userData.tag);
    }
}

在iOS6中,它工作得非常好。但在iOS7中,在数组[i][1]是我想要的,但在cell.userData.text后setText是空的,setTag后一切都是0。cell是UITableView的一部分UITableView是控制器的子视图userData是cell中的UITextField

[self.tableView cellForRowAtIndexPath:...]

对于当前不可见的行返回nil(也可能返回nil)一般在viewWillAppear:)。在这种情况下,cell.userDatanil,设置文本或标签根本不起作用。

看来你在使用将表视图单元格作为数据源。由于上述原因,这是行不通的因为表视图单元格被重用

您必须在

中填充单元格内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

方法。

我认为你应该使用UITableViewDataSource/cellForRowAtIndexPath方法来配置你的单元格的数组[I][1]

像这样:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; {
    return [array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VVUserInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VVUserInformationCellID"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] @"VVUserInformationCell" owner:nil options:nil] objectAtIndex:0];
    }
    [cell.userData setText:array[indexPath.row][1]];
    [cell.userData setTag:indexPath.row]
    return cell;
}

相关内容

最新更新