嗨,我想创建一个天气应用程序。我的天气应用程序是这样的,当用户单击天气选项卡时,当前位置的天气详细信息应显示在表格视图中。对于相同的当前位置,当天、第二天和的天气详细信息后天应该显示在tableview中。请任何人给我任何类型的代码或任何关于如何在iphone中实现这一点的链接。谢谢
3356 次
2 回答
2
你将不得不使用NSDate
,
首先构造一个NSDate
具有当前时间的对象
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
NSString *currentDate = [dateFormatter stringFromDate:today];
现在currentDate
是字符串对象,您可以UILabel
在屏幕上显示它,
同样,您可以创建日期并获取第二天的字符串对象.....
天气API
这些不是 iPhone 特有的,而是免费的天气 API。
示例:http ://weather.yahooapis.com/forecastrss?p=90210
Google Weather API - 这个的文档 URL?
示例:http ://www.google.com/ig/api?weather=90210
示例:http ://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=90210
天气频道- 需要注册
示例:在 github找到示例代码。用于访问 Weather Channel XML API 的 Ruby gem
WeatherAPI(挪威)
示例:http ://api.yr.no/weatherapi/locationforecast/1.6/?lat=34;lon=-118
于 2011-04-25T05:34:30.443 回答