ios - 点击UISearchBar 呼唤不出键盘
伊谢尔伦
伊谢尔伦 2017-04-17 13:45:09
[iOS讨论组]

在做自己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];
    }];
}
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
天蓬老师

模拟器上commond+K

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号