开发者

Segment Button is not displaying on the navigation bar in iphone

Hello I am having problem in displaying segmented button on the navigation bar I try this code it's not working I have the Tab Bar For calling this tabBar I use This code TabBar is working fine but Button on the navigation bar is not displaying

- (v开发者_运维百科oid)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];
}

And right this code into the TMapViewController.m for calling The button onto the navigation bar

-(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, 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;
}

Same thing i use into the - (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, 0, 50, 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];

} even it not work it give me same error . Thanks in advance Harish


Set it as [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, 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜