如何解决分段按钮未显示在iPhone的导航栏中
| 你好 我在导航栏上显示分段按钮时遇到问题 我尝试此代码不起作用 我有标签栏用于调用此标签栏 这段代码TabBar正常工作,但导航栏上的Button不显示- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITabBarController *tabcontroller = [[UITabBarController alloc] init];
UITabBarController *vc1 = [[TMapViewController alloc] init];
UITabBarController *vc2 = [[TShareController alloc]init];
UITabBarController *vc3 = [[TSpeedometerController alloc]init];
UITabBarController *vc4 = [[TReviewsController alloc]init];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3,vc4,nil];
[tabcontroller setViewControllers:viewControllers];
[vc1 release];
[vc2 release];
[vc3 release];
[vc4 release];
[self.navigationController pushViewController: tabcontroller animated: YES];
}
然后将此代码放入TMapViewController.m中以进行调用
导航栏上的按钮
-(id)init
{
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@\"Map\"];
UIImage *i = [UIImage imageNamed:@\"mapper_f.png\"];
[tbi setImage:i];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@\"Activitieslist.png\"],nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0,50,35);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
return self;
}
我用到的同样的东西
-(void)viewDidLoad {
[super viewDidLoad];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@\"Activitieslist.png\"],nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0,35);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
[[self.navigationBar topItem] setTitleView:segmentedControl];
[[[self.navigationBar topItem] titleView] setUserInteractionEnabled:YES];
TLocationManager *manager = [[TLocationManager alloc] init];
self.locationManager = manager;
self.locationManager.delegate = self;
[manager release];
TMapRoutes *routes = [[TMapRoutes alloc] init];
self.mapRoutes = routes;
self.mapRoutes.mapView = self.myMapView;
[routes release];
self.myMapView.delegate = self;
/* Run the simulator */
[locationManager startUpdatingLocation];
}
即使它不起作用,也会给我同样的错误。
提前致谢
ish
解决方法
设置为
[self.navigationBar titleView:segmentedControl]
-(void)loadView {
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@\"Map\"];
UIImage *i = [UIImage imageNamed:@\"mapper_f.png\"];
[tbi setImage:i];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@\"Activitieslist.png\"],nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0,50,35);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
[[self.navigationBar topItem] setTitleView:segmentedControl]; [[[self.navigationBAr topItem] titleView] setUserInteractionEnabled:YES];
[segmentBarItem release];
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。