• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - UIBarButtonItem 没有出现

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:17:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个问题,当 View 被加载时,它会加载 UIBarButtonItem,但是我必须在“mostra_filtro_btn”中将它设置为 nil,但是在“load_map”中我必须再次设置它,但它没有不出现。 这是我的代码:

//
//  FirstViewController.m
//  House Finder
//
//  Created by Giovanni Poli on 12/05/15.
//  Copyright (c) 2015 Giovanni Poli. All rights reserved.
//

#import "MapViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Reachability.h"
#import "UIKit/UIKit.h"
#import <Foundation/Foundation.h>
#import "FiltroViewController.h"

@interface MapViewController ()

@end

@implementation MapViewController
@synthesize filtro_controller,overlay_filtro_counter,mappa_controller;



-(void)load_map{
    NSLog(@"load_map");
    [mapView removeFromSuperview];
    [mappa_controller.view removeFromSuperview];
    [filtro_controller.view removeFromSuperview];

    UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle"Filtro" style:UIBarButtonItemStyleBordered target:self actionselector(mostra_filtro_btn];
    [Button setTitle"Filtro"];
    [Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = Button;
}

- (id) init{
    filtro_controller = [[FiltroViewController alloc]init];
    [self.view addSubview:filtro_controller.view];
    [self addChildViewController:filtro_controller];
    return self;
}


- (void)viewDidLoad {
    self.title = @"Mappa";
    self.navigationItem.title = @"House Finder";
    self.navigationController.navigationBar.translucent = FALSE;
    UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle"Filtro" style:UIBarButtonItemStyleBordered target:self actionselector(mostra_filtro_btn];
    [Button setTitle"Filtro"];
    [Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = Button;

    NSString *filePath = [[NSBundle mainBundle] pathForResource"data" ofType"json"];
    NSData *content = [[NSData alloc] initWithContentsOfFile:filePath];
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:content options:kNilOptions error:nil];
    NSArray * json_all = [json objectForKey"results"];






    mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-40)];
    mapView.delegate = self;
    mapView.showsUserLocation = NO;
    mapView.userInteractionEnabled = YES;
    CLLocationCoordinate2D annotationCoord;
    self.view.userInteractionEnabled = YES;

    NSDictionary * temp;
    for (id object in json_all) {
        temp = object[@"titolo"];
        annotationCoord.latitude = [object[@"lat"] floatValue];
        annotationCoord.longitude = [object[@"lon"] floatValue];
        MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
        annotationPoint.coordinate = annotationCoord;
        annotationPoint.title = object[@"titolo"];
        annotationPoint.subtitle = object[@"agenzia"];
        [mapView addAnnotation:annotationPoint];
    }

    [mapView showAnnotations:[mapView annotations] animated:YES];
    [self.view addSubview:mapView];
    [self.view setNeedsDisplay];
}


- (IBAction) mostra_filtro_btn: (id)sender{
    NSLog(@"mostra_filtro_btn");
    self.navigationItem.rightBarButtonItem = nil;


    filtro_controller = [[FiltroViewController alloc]init];
    [self.view addSubview:filtro_controller.view];
    [self addChildViewController:filtro_controller];
}







- (MKAnnotationView *)mapViewMKMapView *)mapViews viewForAnnotation:annotation{
    if (annotation == mapViews.userLocation) return nil;
    MKPointAnnotation * temp = annotation;
    MKAnnotationView * m = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier"casa"];
    m.canShowCallout = YES;
    m.enabled = YES;
    m.userInteractionEnabled = YES;
    NSString * icon_file = [NSString stringWithFormat:@"%@.png",temp.subtitle];
    m.image = [UIImage imageNamed:icon_file];
    return m;
}


- (void)mapViewMKMapView *)mapView didSelectAnnotationViewMKAnnotationView *)view{
    NSLog(@"overlay prezzo");

}




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

@end



Best Answer-推荐答案


使用以下代码将导航项设置为 nil,以便它可以隐藏在您想要的任何位置

[self.navItem setRightBarButtonItem:nil];
[self.navItem setLeftBarButtonItem:nil];

关于ios - UIBarButtonItem 没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30214596/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap