我正在为 iOS 编写一个表格视图应用程序,而天气是我正在实现的东西。
在我的第一部分(第 0 部分)中,我有 9 行 (0-8) 的基本数据。
-(NSArray *)currentDataValues
{
return @[
[self dataValueForKey:@"cloudCover"],
[self dataValueForKey:@"dewPoint"],
[self dataValueForKey:@"humidity"],
[self dataValueForKey:@"precipIntensity"],
[self dataValueForKey:@"precipProbability"],
[self dataValueForKey:@"temperature"],
[self dataValueForKey:@"visibility"],
[self windDirection:[self.currentValuesDict valueForKey:@"windBearing"]],
[self dataValueForKey:@"windSpeed"]];
}
然后在我的 cellForRowAtIndexPath 中,我有以下内容。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier;
if (indexPath.section == 0) {
cellIdentifier = @"Summary Cell";
} else {
cellIdentifier = @"Minutely Cell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}
if([indexPath section] == 0){
cell.textLabel.text = [self.currentDataPoints objectAtIndex:[indexPath row]];
cell.detailTextLabel.text = [self.currentDataValues objectAtIndex:[indexPath row]];
}
现在,一切正常。细胞生成就像他们期望的那样,并且它按照我设想的方式工作。
问题/问题。
正如您在 currentDataValues 方法中注意到的那样,有一次我正在调用另一种方法来返回风向,它看起来像这样(为了简洁而缩短)。
-(NSString *)windDirection:(NSNumber *)value
{
NSLog(@"%@", value);
if (value.floatValue > 11.25 && value.floatValue < 33.75) {
return @"North North East";
} else if (value.floatValue > 33.75 && value.floatValue < 56.24) {
return @"North East";
}
}
我有登录在那里进行测试,这就是问题所在。当该方法被调用时,我得到 9 条日志消息,而我应该只得到 1 条。
2013-07-10 16:19:13.502 XX Weather[48831:c07] 260
2013-07-10 16:19:13.503 XX Weather[48831:c07] 260
2013-07-10 16:19:13.503 XX Weather[48831:c07] 260
2013-07-10 16:19:13.503 XX Weather[48831:c07] 260
2013-07-10 16:19:13.504 XX Weather[48831:c07] 260
2013-07-10 16:19:13.504 XX Weather[48831:c07] 260
2013-07-10 16:19:13.504 XX Weather[48831:c07] 260
2013-07-10 16:19:13.505 XX Weather[48831:c07] 260
2013-07-10 16:19:13.505 XX Weather[48831:c07] 260
我不得不假设这会导致性能问题,我不明白为什么会这样。