工具栏按钮图标(pagecurl)未加载

发布于 2024-12-18 16:31:51 字数 2360 浏览 4 评论 0原文

我正在加载地图视图。我在视图的底栏工具栏中创建了一个栏按钮,将其标识符设置为 pagecurl。正如预期的那样,加载了带有卷页图标的栏按钮。通过单击地图视图中的注释,我从该地图视图移至另一个视图。然后我返回到地图视图。那时我的pagecurl barbutton图标(pagecurl icon)没有显示,并且我的barbutton宽度也减少了。我无法找出问题所在。

- (void)viewDidLoad
{
    [super viewDidLoad];

    if(isSingleContactSelected)
    {
        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        self.navigationItem.leftBarButtonItem = self.cancelButton   ;
        [self.cancelButton setTarget:self];
        [self.cancelButton setAction:@selector(onClose:)];

        [addressFieldSearchBar setFrame:CGRectMake(66, 0, 256, 44)];
        addressFieldSearchBar.delegate =self;

        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        [self.navigationController.navigationBar addSubview:addressFieldSearchBar];

        [searchDirectionSegmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        UIBarButtonItem *searchDirectionSegmentedButton = [[UIBarButtonItem alloc] initWithCustomView:searchDirectionSegmentedControl];

        flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        NSArray *toolbarItems = [NSArray arrayWithObjects: compassButton , flexibleSpace, searchDirectionSegmentedButton, flexibleSpace, pageButton, nil];
        [self setToolbarItems:toolbarItems];

        self.navigationController.toolbarHidden = NO;
        [compassButton release];
        [pageButton release];
        [searchDirectionSegmentedControl release];

        mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        mapView.delegate=self; 

        [self.view addSubview:mapView]; 
    }
}

- (void)viewDidUnload{
    [super viewDidUnload];    
}

-(void) viewWillAppear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.navigationController.navigationBar setHidden:NO];
        [self.navigationController.toolbar setHidden:NO];
        [self.navigationController.toolbar setBarStyle:UIBarStyleDefault];
        [self.addressFieldSearchBar setHidden:NO];
    }
}

-(void) viewWillDisappear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.addressFieldSearchBar setHidden:YES];
        [self.navigationController.toolbar setHidden:YES];
    }
}

I am loading a mapview. I have created a barbutton in the bottombar toolbar of the view, setting its identifier as pagecurl. As expected, a barbutton with page curl icon is loaded. From this mapview I move to anotherv view, by clicking on annotations in the mapview. And then I return to the mapview. At that time my pagecurl barbutton icon(pagecurl icon) is not displayed, and my barbutton width is also reduced. I am not able to figure out the problem.

- (void)viewDidLoad
{
    [super viewDidLoad];

    if(isSingleContactSelected)
    {
        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        self.navigationItem.leftBarButtonItem = self.cancelButton   ;
        [self.cancelButton setTarget:self];
        [self.cancelButton setAction:@selector(onClose:)];

        [addressFieldSearchBar setFrame:CGRectMake(66, 0, 256, 44)];
        addressFieldSearchBar.delegate =self;

        [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
        [self.navigationController.navigationBar addSubview:addressFieldSearchBar];

        [searchDirectionSegmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        UIBarButtonItem *searchDirectionSegmentedButton = [[UIBarButtonItem alloc] initWithCustomView:searchDirectionSegmentedControl];

        flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        NSArray *toolbarItems = [NSArray arrayWithObjects: compassButton , flexibleSpace, searchDirectionSegmentedButton, flexibleSpace, pageButton, nil];
        [self setToolbarItems:toolbarItems];

        self.navigationController.toolbarHidden = NO;
        [compassButton release];
        [pageButton release];
        [searchDirectionSegmentedControl release];

        mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        mapView.delegate=self; 

        [self.view addSubview:mapView]; 
    }
}

- (void)viewDidUnload{
    [super viewDidUnload];    
}

-(void) viewWillAppear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.navigationController.navigationBar setHidden:NO];
        [self.navigationController.toolbar setHidden:NO];
        [self.navigationController.toolbar setBarStyle:UIBarStyleDefault];
        [self.addressFieldSearchBar setHidden:NO];
    }
}

-(void) viewWillDisappear:(BOOL)animated{
    if(isSingleContactSelected){
        [self.addressFieldSearchBar setHidden:YES];
        [self.navigationController.toolbar setHidden:YES];
    }
}

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

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

发布评论

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

评论(2

我不是你的备胎 2024-12-25 16:31:51

虽然可能性不大,但可能与您的出现和消失方法中的 setHidden 调用有关。

[self.navigationController.toolbar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];

最好的方法是使用 UIViewController 的“-setHidesBottomBarWhenPushed:”方法。

也许在 -viewWillAppear 中尝试一些 NSLog() :

// If pageButton is an instance variable
NSLog(@"%@",pageButton);

// Enumerate through all toolbar items.
// Check to see if NSLog output differs after pushing/popping this view controller.
for (UIBarButtonItem *item in [self.navigationController.toolbar.items])
{
    NSLog(@"%@",item);
}

Though its a long shot, it could be something to do with the setHidden calls in your appear and disappear methods.

[self.navigationController.toolbar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];

The best way to do this using UIViewController's "-setHidesBottomBarWhenPushed:" method.

Maybe try some NSLog() in -viewWillAppear:

// If pageButton is an instance variable
NSLog(@"%@",pageButton);

// Enumerate through all toolbar items.
// Check to see if NSLog output differs after pushing/popping this view controller.
for (UIBarButtonItem *item in [self.navigationController.toolbar.items])
{
    NSLog(@"%@",item);
}

setHidesBottomBarWhenPushed 方法在这种情况下达到了目的。

setHidesBottomBarWhenPushed method did the trick in this case.

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