How to get a value from a delegate and reload a view
I'm developing an iPad app, and it's the first time I put the popover view 开发者_StackOverflowto good use. I'm using the popover view as a menu with categories, and only have 1 screen with video's. When the user selects a category, the 'FeaturedViewController' has to reload the view with the new playlistId.
When a user selects a category, it's easy to do: double playlistId = [[playlists.items objectAtIndex:indexPath.row] playlistId];
But how do I get that playlistId in my FeaturedViewController and reload the view?
in your FeaturedViewController.m
- (void)viewDidLoad
{
//create reference of your delegate
YourAppDelegate rootApp = (YourAppDelegate *)[[UIApplication sharedApplication]delegate];
double playlistId = [[[[rootApp playlists] items] objectAtIndex:indexPath.row] playlistId ];
[super viewDidLoad];
}
EDITED
Or you can define a property in FeaturedViewController and assign value in this VC like :
FeaturedViewController nextView = [[FeaturedViewController alloc] initWithNibName:@"FeaturedViewController" bundle:nil];
//below lineset the value of property and you can pass value to nextView
nextView.playlistId = [[playlists.items objectAtIndex:indexPath.row] playlistId]; ;
[self.navigationController pushViewController:nextView animated:YES];
hope it gives you idea to access variable of delegate
Look:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// load new playlist
BCPlaylist *playlist = (BCPlaylist *) [playlists.items objectAtIndex:indexPath.row];
NSNumber *key = [NSNumber numberWithDouble:playlist.playlistId];
NSLog(@"Key: %@", key);
FeaturedViewController *nextView = [[FeaturedViewController alloc] initWithNibName:nil bundle:nil];
nextView.PLID = key;
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
The Key NSlogs correctly, but i dont get a response from nextView.PLID in the FeaturedViewController at all.
精彩评论