首页 > 点击UISearchBar 呼唤不出键盘

点击UISearchBar 呼唤不出键盘

在做自己ios天气应用的时候,用到UISearchBar,可是不知道为什么点击后没有键盘出现,麻烦看看我的代码是不是有什么问题。代码如下

#import "SketchWeatherViewController.h"
#import "OWMWeatherAPI.h"

@interface SketchWeatherViewController () <UISearchBarDelegate>
{
    OWMWeatherAPI *_weatherAPI;
    NSArray *_forecast;
    NSDateFormatter *_dateformatter;
    int downloadCount;
    int count;
}

@end

@implementation SketchWeatherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    _forecast = @[];

    _weatherAPI = [[OWMWeatherAPI alloc] initWithAPIKey:@"53bcc818743498ea24bebe70cf2cba0a"];
    [_weatherAPI setLangWithPreferedLanguage];
    [_weatherAPI setTemperatureFormat:kOWMTempCelcius];

    self.searchbar.delegate = self;
    self.searchbar.placeholder = [NSString stringWithFormat:@"搜索你的城市"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UISearchBarDelegate

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchbar{

    [self.activityIndicator startAnimating];

    [_weatherAPI currentWeatherByCityName:self.searchbar.text withCallback:^(NSError *error, NSDictionary *result) {

        downloadCount++;

        if (downloadCount > 1) [self.activityIndicator stopAnimating];

        if (error) {
            // Handle the error
            return;
        }

        self.sunIcon.image = [UIImage imageNamed:@"01d"];
        self.moonIcon.image = [UIImage imageNamed:@"01n"];
        self.weatherIcon.image = [UIImage imageNamed:result[@"weather"][@"Icon"]];
        self.cityName.text = [NSString stringWithFormat:@"%@, %@", result[@"name"],result[@"sys"][@"country"]];
        self.cityWeather.text = [NSString stringWithFormat:@"%d℃,%@", (int)result[@"main"][@"temp"],result[@"weather"][0][@"description"]];
        self.sunriseTime.text = [_dateformatter stringFromDate:result[@"sys"][@"sunrise"]];
        self.sunsetTime.text = [_dateformatter stringFromDate:result[@"sys"][@"sunset"]];
    }];


    [_weatherAPI dailyForecastWeatherByCityName:self.searchbar.text withCount:count andCallback:^(NSError *error, NSDictionary *result){

        downloadCount++;

        if (downloadCount > 1) [self.activityIndicator stopAnimating];

        if (error) {
            // Handle the error
            return;
        }
        _forecast = result[@"list"];
        [self.tableview reloadData];
    }];
}

模拟器上commond+K

【热门文章】
【热门文章】