我有一个 View ,其中顶部有一个按钮,底部有一个带有自定义单元格的表格 View
自定义单元格我有一个文本字段,我试图通过点击顶部的那个按钮来访问 tableview 单元格之外的文本字段内容以获取行方法,如果我滚动到顶部并点击,则只显示可见的单元格文本保存时,底部文本字段值为零,如果我滚动到底部并点击保存底部文本字段值为零,我想这与带有标识符的可恢复单元格出列有关。
//表格 View 方法
- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *simpleTableIdentifier = @"AcessoryCell";
AcessoryCell *cell = (AcessoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AcessoryCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
}
for (NSInteger i=0; i<selectedButtonsArray.count; i++)
{
NSNumber * num = [selectedButtonsArray objectAtIndex:i];
NSIndexPath * indexPath=[NSIndexPath indexPathForRow:[num intValue] inSection:0];
AcessoryCell *cell = (AcessoryCell *) [self.acessoryTableView cellForRowAtIndexPath:indexPath];
NSLog(@"text field text is %@", cell.celltextField.text);
}
日志是
text is 1
text is 1
text is 1
text is 1
text is 1
text is 1
text is (null)
text is (null)
如果我滚动到底部然后日志是
text is (null)
text is (null)
text is 1
text is 1
text is 1
text is 1
text is 1
text is 1
最佳答案
尝试一下它的工作原理:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:YOUR_ROW inSection:YOUR_SECTION];
UITableViewCell* cell = [yourTable cellForRowAtIndexPath:indexPath];
cell.textLabel.textColor = YOUR_COLOR;
[yourTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
关于ios - 访问 cellforrow 之外的 tableview 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26709483/