danny huang
danny huang

Reputation: 155

I cannot save retrieve NSurl from another class?

I have a function that returns a NSUrl, and i want to use it in another class. But when i tried to retrieve it in my other class, it gives me null. This is my First Class

@interface UOEventDetailController : UIViewController {
NSURL *imgData;
}
@property(nonatomic, retain)NSURL *imgData;
-(NSURL *)imgData;

@implementation UOEventDetailController
@synthesize imgData;

The .m File

-(NSURL *)imgData{
UOEventPost *post = (UOEventPost *)self.event;
NSURL *url = [NSURL URLWithString:post.postImageURL];
return url;
}

I want to retrieve the URL in this class

@class UOEventDetailController;

@interface UOEnlargeImageViewController : UIViewController {
IBOutlet UIImageView *enlargedImage;

}
@property (nonatomic, retain) UOEventDetailController *controller;
@property (nonatomic, retain) IBOutlet UIImageView *enlargedImage;

the .m file

@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

I can retrieve objects other than post.postImageUrl. For Example instead of post.postImageUrl, i put in string like @"omg", @"god" it gets retrieved in my other class...

EDIT

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

Upvotes: 0

Views: 87

Answers (2)

Abhishek Singh
Abhishek Singh

Reputation: 6166

The Object will be null as a new object is being created and it's not in same state as you want it , you must use protocol & delegate to pass the object to another class if flow is backward else ensure that you work on the same object.

Upvotes: 0

Saad
Saad

Reputation: 8947

this is because you are making a new object. and that of new object, relevent attributes are empty and hence url is also null.

Upvotes: 1

Related Questions