从Tableview获取数据到包含Tableview的Viewcontroller

时间:2014-10-08 23:15:11

标签: ios uitableview ios8

我尝试在两个表视图之间传递数据,例如,当人们点击第一个表视图中的一行时,您将在第二个表视图中看到更多数据。实际上,应用程序运行但第二个表视图中没有数据。 / p>

2 个答案:

答案 0 :(得分:0)

您的标题标签是否出现?然后问题可以缩小到PFFile对象的东西。

首先,您应该确保要显示的任何图像都是从Parse服务器下载并存储在内存中的。说到Parse对象,PFFile(image)只是对Parse服务器中实际文件的引用。因此,您应该在本地使用之前下载实际图像,例如在图像视图中设置它。

从服务器获取单个图像PFFile:

PFFile *file = dictionary[@"thumbnail"];
[file getDataInBackgroundWithBlock:^(NSData *thumbnailData, NSError *error) {
    if (!error) {  // downloaded successfully 
      UIImage *image = [UIImage imageWithData:thumbnailData];
      ....
    }
 }

在您的情况下,似乎多个图像存储在newspaper数组中,因此如果您想要访问其中一个图像,则必须首先下载所有图像。然后重新加载第二个表视图数据。

准备' dictionaryOfNewspaperImage'并覆盖第二个vc中的viewDidAppear方法,如下所示:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    for (int i = 0; i < [self.arrayofnewspaper count]; i++) {        
        PFFile *file = self.arrayofnewspaper[i];
        [file getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
            if (!error) {
                UIImage *image = [UIImage imageWithData:imageData];
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:1];
                [self.dictionaryOfNewspaperImage setObject:image forKey:indexPath];
                [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            }
        }
    }
}

您的单元格配置部分应如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ....
    cell.imageView.image = self.dictionaryOfNewspaperImage[indexPath];
    ....
    return cell;
}

不太确定使用NSIndexPath作为密钥是否可靠,应该有更好的方法,但是你会得到这个想法。首先从Parse获取文件,然后重新加载相关的行。

答案 1 :(得分:0)

更改第二个表的数据源时,需要通过调用其reloadData方法通知更改表。

在这种情况下,它可能是

destviewcontroller.arrayofnewspaper=[object objectForKey:@"newspaper"];
[destviewcontroller.table reloadData];
相关问题