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

发布于 2024-11-27 07:48:45 字数 304 浏览 0 评论 0原文

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

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

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

I'm developing an iPad app, and it's the first time I put the popover view to 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榕城若虚 2024-12-04 07:48:45

在您的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];

希望它能给您提供访问委托变量的想法

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

好久不见√ 2024-12-04 07:48:45

看:

- (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 NSlogs 正确,但我根本没有从 FeaturedViewController 中的 nextView.PLID 得到响应。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文