iPhone:在 MPMoviePlayerViewController 的导航栏上添加按钮

发布于 2024-11-19 14:03:44 字数 1250 浏览 7 评论 0原文

我正在尝试在 MPMoviePlayerViewController 的 navigationcontroller.view 上添加按钮。到目前为止我已经写了以下内容。它没有给出任何错误,但按钮没有出现在视图中!谁能告诉我我做错了什么吗?谢谢。

        MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
        UIButton *favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        favButton.frame = CGRectMake(280, 25, 30, 30);
        [favButton addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [favButton setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
        [videoController.navigationController.view addSubview:favButton];
        [self presentMoviePlayerViewControllerAnimated:videoController];


- (void)favouriteButtonClicked:(id)sender
{
    NSLog(@"Inside favourite button clicked");
}

还尝试使用以下代码添加,但没有成功!

        UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
        videoController.navigationController.navigationItem.rightBarButtonItem=button; 
        [button release];

I am trying to add button on MPMoviePlayerViewController's navigationcontroller.view. I have wrote following so far. It doesn't give any error but button isn't appearing on view! Could anyone please tell me what am I doing wrong? Thanks.

        MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
        UIButton *favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        favButton.frame = CGRectMake(280, 25, 30, 30);
        [favButton addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [favButton setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
        [videoController.navigationController.view addSubview:favButton];
        [self presentMoviePlayerViewControllerAnimated:videoController];


- (void)favouriteButtonClicked:(id)sender
{
    NSLog(@"Inside favourite button clicked");
}

Also try adding using following code but no luck!

        UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
        videoController.navigationController.navigationItem.rightBarButtonItem=button; 
        [button release];

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

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

发布评论

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

评论(3

深白境迁sunset 2024-11-26 14:03:44
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
videoController.navigationItem.rightBarButtonItem = button; 
[button release];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
videoController.navigationItem.rightBarButtonItem = button; 
[button release];
梦初启 2024-11-26 14:03:44

如果您使用presentModalViewController,则看不到您添加的按钮。你必须 [self.navigationController PushViewController:moviePlayeranimated:YES] 才能看到它。

If you use presentModalViewController, you can not see the button you add. You have to [self.navigationController pushViewController:moviePlayer animated:YES] to see it.

残月升风 2024-11-26 14:03:44

试试这个..它会起作用

[[[UIApplication sharedApplication] keyWindow] addSubview:favButton];

Try this..it will work

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