【发布时间】:2011-07-08 15:56:49
【问题描述】:
我正在为大学开发一个位置感知应用程序,其中一个要开发的功能包括显示最接近用户的前五个兴趣点。我正在使用一个表格视图,其单元格样式为 UITableViewCellStyleSubtitle。我遇到了一些问题,因为除了单元格的标题和副标题之外,我正在使用图像(箭头)来显示用户到达 POI 应遵循的方向。只要设备的航向/位置发生变化,该图像就会旋转。问题是只有表格视图的最后一行有效,主要问题是我不知道如何使用五个不同的单元格,因为每个 POI 可以有不同的位置,而不是设备的位置,因此每个单元格的图像应该独立旋转。 我报告了一张图片,以便更好地了解我的问题。
下面是我用于表格视图单元格的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableIdentifier = @"tableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
NSUInteger row = [indexPath row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Distance: %.3f Km",[...];
UIImage *cellImage = [UIImage imageNamed:@"arrow.png"];
cell.imageView.image = cellImage;
self.cellImageView = cell.imageView;
return cell;
}
关于如何使用 5 个不同的单元格来为每个箭头提供直角的任何想法?!
谢谢
【问题讨论】:
-
你能告诉我你是如何为 UIImageView 添加标题的吗?你可以在这里分享你的代码。我会尽快给你答复。
-
你如何更新你的细胞?
-
在表格视图的视图控制器中,我为 UIImageView 定义了一个属性,该属性将在设备更改其标题时立即更新。在上面的方法中,outlet 是通过 self.cellImageView = cell.imageView; 来初始化的。当设备更改其标题时,委托使用 CGAffineTransformMakeRotation(angle) 更新 imageView。
标签: iphone ios uitableview