gpt4 book ai didi

ios - NSURL 未在 View Controller 之间传递

转载 作者:行者123 更新时间:2023-11-29 03:22:27 24 4
gpt4 key购买 nike

我正在一个 View Controller 中创建一个 NSURL ,然后在另一个 View Controller 中使用它。 URL 在创建它的 View Controller 中包含正确的字符串,但在我将其传递到的 View Controller 中,它是 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];

这是我将其传递给另一个 View Controller 的地方:

- (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];

}

在 secondaryviewcontroller.h 中:

@property (strong, nonatomic) NSURL *finalURL;

在 secondaryviewcontroller.m 中:

AVAsset *asset = [AVURLAsset URLAssetWithURL:self.finalURL options:nil];

最佳答案

您做的是正确的,但是您又创建了一个 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];

}

关于ios - NSURL 未在 View Controller 之间传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20916697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com