在做自己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];
}];
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。