Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将解析文件传递给新的视图控制器_Ios_Objective C_Parse Platform_Uiviewcontroller - Fatal编程技术网

Ios 如何将解析文件传递给新的视图控制器

Ios 如何将解析文件传递给新的视图控制器,ios,objective-c,parse-platform,uiviewcontroller,Ios,Objective C,Parse Platform,Uiviewcontroller,我试图将包含图像的PFile传递给新的图像视图控制器,但似乎无法成功传递该文件 下面是我试图传入文件的代码 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { PurchaseItemViewController*purchaseItemViewController = [[PurchaseItemViewController alloc] initWithN

我试图将包含图像的PFile传递给新的图像视图控制器,但似乎无法成功传递该文件

下面是我试图传入文件的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

PurchaseItemViewController*purchaseItemViewController = [[PurchaseItemViewController alloc] initWithNibName:Nil bundle:Nil];
NSLog(@"%@",indexPath);
NSInteger row = indexPath.row;

purchaseItemViewController.objectID = _objectIDArray[row];
purchaseItemViewController.imageData = _bookImageData[row];
purchaseItemViewController.authorOfBook = _authorNameArray[row];
purchaseItemViewController.titleOfBook = _bookNameArray[row];

purchaseItemViewController.bookCoverImageView.file =_bookImageData[row];

NSLog(@"HERE IS THE DATA %@",_bookImageData[row]);
NSLog(@"here is the file %@",purchaseItemViewController.bookCoverImageView.file);

[purchaseItemViewController.bookCoverImageView loadInBackground];
 // purchaseItemViewController 
// Push the view controller.
[self presentViewController:purchaseItemViewController animated:NO completion:Nil];
}

当我执行代码时,我得到以下注销

016-02-09 14:36:33.265项目[17786:7270793]这里是数据“PFFile:0x7fbe12f7dcb0”

2016-02-09 14:36:33.266项目[17786:7270793]这是文件(空)

谁能告诉我我做错了什么?
谢谢

问题在于,在运行此代码时,视图控制器尚未准备好配置其视图(例如,
bookCoverImageView

正确的步骤顺序是按照您的方式构建
purchaseItemViewController
,从数据源设置属性,然后呈现它。不要尝试配置其视图或加载图像

PurchaseItemViewController*purchaseItemViewController = [[PurchaseItemViewController alloc] initWithNibName:Nil bundle:Nil];
NSLog(@"%@",indexPath);
NSInteger row = indexPath.row;

purchaseItemViewController.objectID = _objectIDArray[row];
purchaseItemViewController.imageData = _bookImageData[row];
purchaseItemViewController.authorOfBook = _authorNameArray[row];
purchaseItemViewController.titleOfBook = _bookNameArray[row];

// TOO EARLY FOR THIS:  
// purchaseItemViewController.bookCoverImageView.file =_bookImageData[row];

NSLog(@"HERE IS THE DATA %@",_bookImageData[row]);
// TOO EARLY FOR THIS:
// NSLog(@"here is the file %@",purchaseItemViewController.bookCoverImageView.file);

//  TOO EARLY FOR THIS:
// [purchaseItemViewController.bookCoverImageView loadInBackground];
[self presentViewController:purchaseItemViewController animated:NO completion:Nil];
您必须配置视图的第一次机会将出现在
PurchaseItemViewController
中的
viewDidLoad
中。在那里,你可以说

PFFile *file = self.imageData;  // this is a PFFile with a confusing name
self.bookCoverImageView.file = file;
[self.bookCoverImageView loadInBackground];

再次感谢你的帮助!很乐意帮忙。顺便提一下,我想在另一个问题上提到,与其为获取的对象的每个属性设置一个数组,不如只保留一个查询返回的PFObjects数组?然后您可以一次获得所有属性。这是一个非常明智的建议,我将尝试实现它。:-),然后在这个问题中对新的视图控制器也是如此。您可以只传递一个PFObject,而不是它的4或5个属性。