我在一个视图控制器中创建NSURL
,然后在另一个视图控制器中使用它。 URL包含正在创建它的视图控制器中的正确字符串,但在我传递给它的视图控制器中,它是NULL
。
NSData *data = feed.imageData;
NSData *stringData = feed.urlString;
self.stringForURL = [[NSString alloc] initWithData:stringData encoding:NSUTF8StringEncoding];
self.stringForURL = [self.stringForURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
self.finalURL = [NSURL URLWithString:self.stringForURL];
这是我将它传递给另一个视图控制器的地方:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// Code to create detailed view and set properties
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.managedObjectContext = self.managedObjectContext;
detailViewController.managedObject = object;
NSLog(@"Here is the final URL:%@", [self.finalURL absoluteString]);
detailViewController.finalURL = self.finalURL;
DetailViewController *detailsViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailsViewController animated:YES];
}
在secondviewcontroller.h中:
@property (strong, nonatomic) NSURL *finalURL;
在secondviewcontroller.m中:
AVAsset *asset = [AVURLAsset URLAssetWithURL:self.finalURL options:nil];
答案 0 :(得分:1)
你做得对,但你又创建了一个detailViewController实例并推送它。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// Code to create detailed view and set properties
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.managedObjectContext = self.managedObjectContext;
detailViewController.managedObject = object;
NSLog(@"Here is the final URL:%@", [self.finalURL absoluteString]);
detailViewController.finalURL = self.finalURL;
[self.navigationController pushViewController: detailViewController animated:YES];
}