我有一个返回 NSUrl 的函数,我想在另一个类中使用它。但是当我试图在我的其他班级中检索它时,它给了我空值。这是我的第一堂课
@interface UOEventDetailController : UIViewController {
NSURL *imgData;
}
@property(nonatomic, retain)NSURL *imgData;
-(NSURL *)imgData;
@implementation UOEventDetailController
@synthesize imgData;
.m 文件
-(NSURL *)imgData{
UOEventPost *post = (UOEventPost *)self.event;
NSURL *url = [NSURL URLWithString:post.postImageURL];
return url;
}
我想检索此类中的 URL
@class UOEventDetailController;
@interface UOEnlargeImageViewController : UIViewController {
IBOutlet UIImageView *enlargedImage;
}
@property (nonatomic, retain) UOEventDetailController *controller;
@property (nonatomic, retain) IBOutlet UIImageView *enlargedImage;
.m 文件
@implementation UOEnlargeImageViewController
@synthesize controller;
@synthesize enlargedImage;
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Enlarged Image";
controller = [[UOEventDetailController alloc]init];
NSURL *url = [controller imgData];
NSLog(@"%@",url);
}
@end
我可以检索 post.postImageUrl 以外的对象。例如,而不是 post.postImageUrl,我输入了像 @"omg"、@"god" 这样的字符串,它在我的其他类中被检索到......
编辑
-(IBAction)enlargeImg{
UOEventPost *post = (UOEventPost *)self.event;
UOEnlargeImageViewController *enlarge = [[UOEnlargeImageViewController alloc]initWithNibName:nil bundle:nil];
enlarge.temp = post.postImageURL;
[self.navigationController pushViewController:enlarge animated:YES];
[suggestPopupView removeFromSuperview];
[enlarge release];
}