简体   繁体   中英

Cannot populate the data inside a ViewController class

I am making a gallery using the Three20, my problem is when I try to create my view to show the gallery my AlbumController isn't populated with the photos get from my previous view. The Photos are there in a NSArray (inputAlbumController) and my title for the next view is in the NSTextField (txtSearch), the application enters the if-statement (self.albumView == nil), I tested them out with NSLog, but when I try to transfer them via the setters on the next view I get nothing. Here is some of the code needed for this problem:

This is the rootViewController.h:

@interface rootViewController : UIViewController {
    AlbumController *albumView;
    IBOutlet UITextField *txtSearch;
}
@property (nonatomic, retain) AlbumController *albumView;

This is in the function from my rootViewController.m:

geoFlickrAppDelegate *appDelegate = (geoFlickrAppDelegate *)[[UIApplication sharedApplication] delegate];
if(self.albumView == nil) {
    [albumView setMyImages:inputAlbumController];
    [albumView setMyTitle:txtSearch.text];
    //self.albumView = album;
    [appDelegate toGallery];
}

[self.navigationController pushViewController:self.albumView animated:YES];

This is my AlbumController.h:

@interface AlbumController : TTThumbsViewController {
    NSArray *myImages;
    NSString *myTitle;
}
@property (nonatomic, retain) NSArray *myImages;
@property (nonatomic, retain) NSString *myTitle;

This is the ViewDidLoad from my AlbumController.m:

- (void)viewDidLoad { 
self.photoSource = [[PhotoSource alloc]  
                    initWithType:PhotoSourceNormal  
                    title:myTitle  
                    photos:myImages  
                    photos2:nil  
                    ];  
} 

Any idea why is this so? Am I missing something?

It's hard to tell what's exactly the issue. For starters, you're not using the standard TTNavigator . It's not required, but it's easier to work with, especially when you use three20 TTViewControllers.

Secondly, AlbumController has to be initialized somewhere (preferable in the app launched function):

AlbumController* _albumContoller = [[AlbumController alloc] init];

I also recommend having the AlbumController object in the AppDelegate and not a part of another UIViewController. It will make things much easier:

[appDelegate.albumView setMyImages:inputAlbumController];
[self.navigationController pushViewController:appDelegate.albumView animated:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM