1

我想迭代所有 uitablewview 单元格并显示每个单元格中包含的 uitextview 的文本。我的表格可以有很多行,并且要达到所有您必须滚动的内容。我做了一个实现,但它只显示滚动中当前可见单元格的文本,因为其他的给我null。

for (int i = 0; i < [propertiesTableView numberOfRowsInSection:0]; i++) {
    UITableViewCell* cell = [propertiesTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
    UITextView* tx = (UITextView*)[cell viewWithTag:2];
    NSString* temp = tx.text;
    NSLog(@"%@", temp);
}

如何解决这个问题?

4

2 回答 2

1

This happens because only the visible cells are instantiated (remember the dequeueReusableCellWithIdentifier: function?). You should extract the needed information from the table data source.

于 2012-05-15T10:56:44.487 回答
0

Yes this behavior is expected, because of performance considerations the table view does not holds all cells initialized all the time. Your solution is just to update your data source - if it's an array for example, iterate though it and change the values accordingly - this is the power of MVC (fast UI, separate model)

于 2012-05-15T10:57:10.717 回答