我一直在研究ipad应用程序。在这个应用程序中,我有几个视图。这是流程
欢迎屏幕>主屏幕>剩下的其他部分
我在所有屏幕的导航栏上应用了主页图标(按钮)。在任何屏幕上按主页图标都会将用户带到主屏幕。我在Home类的viewDidLoad中编写了以下代码
//**** Home button on navigation bar ****//
CGRect frame1 = CGRectMake(975.0, 4.0, 35, 35);
UIImage *buttonImage1 = [UIImage imageNamed:@"HomeIcon.png"];
UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
homeButton.frame = frame1;
[homeButton setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
homeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
homeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[homeButton addTarget:self action:@selector(goHome:) forControlEvents:UIControlEventTouchUpInside];
[homeButton setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar addSubview:homeButton];
此按钮功能正常。 goHome是@selector中应用的方法的名称。 我想从主屏幕中删除此按钮并将其保留在其余屏幕上。我已经应用了几件事,但我不知道该怎么做。这似乎很简单,但我仍然没有得到它。请指导..
此致 PC
答案 0 :(得分:3)
在“主屏幕”viewDidAppear方法中执行以下操作:
for(UIView* view in self.navigationController.navigationBar.subviews)
{
if(view.tag == 10)
{
view.hidden = YES;
}
}
在您创建主页按钮的按钮设置标记为10的其他视图控制器中。
/**** Home button on navigation bar ****//
CGRect frame1 = CGRectMake(975.0, 4.0, 35, 35);
UIImage *buttonImage1 = [UIImage imageNamed:@"HomeIcon.png"];
UIButton *homeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[homebutton setTag:10]; // Set tag to 10 or any value
homeButton.frame = frame1;
[homeButton setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
homeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
homeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[homeButton addTarget:self action:@selector(goHome:) forControlEvents:UIControlEventTouchUpInside];
[homeButton setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar addSubview:homeButton];
在你的viewDidAppear中:这个其他视图控制器:
for(UIView* view in self.navigationController.navigationBar.subviews)
{
if(view.tag == 10)
{
view.hidden = NO;
}
}
答案 1 :(得分:1)
试试这个:
self.navigationItem.backBarButtonItem = nil;