如何从委托中获取值并重新加载视图

时间:2011-07-29 09:31:48

标签: iphone delegates popover

我正在开发一款iPad应用程序,这是我第一次充分利用popover视图。我正在使用弹出视图作为带有类别的菜单,并且只有1个带有视频的屏幕。当用户选择一个类别时,'FeaturedViewController'必须使用新的playlistId重新加载视图。

当用户选择某个类别时,很容易做到:double playlistId = [[playlists.items objectAtIndex:indexPath.row] playlistId];

但是如何在我的FeaturedViewController中获取该播放列表并重新加载视图?

2 个答案:

答案 0 :(得分:0)

您的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

或者您可以在FeaturedViewController中定义属性并在此VC中指定值,如:

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

希望它能让您知道访问委托变量

答案 1 :(得分:0)

查找

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

Key NSlog正确,但我根本没有从FeaturedViewController中的nextView.PLID得到响应。