iPhone:在 MPMoviePlayerViewController 的导航栏上添加按钮
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用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.
试试这个..它会起作用
Try this..it will work