ios - 访问 cellforrow 之外的 tableview 内容

标签 ios objective-c uitableview

我有一个 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/

相关文章:

iphone - 如何在 quartz 2d 中绘制 alpha < 1 的线

ios - 不兼容的 block 指针类型 - Objective-c

ios - 如何访问 UICollectionViewController header 中的 UISegmentedControl?

ios - Concat 运算符 RxSwift

iphone - 如何暂停/播放 NSTimer?

iOS:删除 NSDecimalNumber 中的千位分隔符进行编辑

iphone - Objective-C 的内置 rand() 函数的确切算法是什么?

ios - 如何修复 SIGABRT 错误

swift - 如何在 UITableview 标题中添加自定义控件

iphone - 在iOS上使用后台任务进行UI更新