防止在UITableViewCell里重新加载MKMapView
问题描述:
我已经创建了UITableViewCell的子类并添加了一个MapView。每当我滚动屏幕的地图并回滚到它再次加载的单元格时。 (正如你们都知道这是细胞重复使用的默认行为)防止在UITableViewCell里重新加载MKMapView
有没有办法阻止?或者你知道这种情况下的其他技巧吗?非常感谢!
答
一个可能的解决方案:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSInteger row = [indexPath row];
UITableViewCell *cell = nil;
if(row != kMapCellRow) { // defined value to whatever value it may be
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
else {
// use an ivar to track the map cell, should be set to nil in class init
cell = _mapCell;
}
if (cell == nil) {
if(row != kMapCellRow) { // defined value to whatever value it may be
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
else {
// create your map cell here
cell = [[[MyTableViewMapCell alloc] init...
}
}
// configure it here
你可以用一个实例变量替换定义kMapCellRow如果是有意义的,你的应用程序。
有多少个细胞..?单个或多个地图。 – aahsanali
单元格中的地图很奇怪,用户如何滚动tableview? – jbat100
有2到10个单元格。单元格中的地图根本不奇怪。如果您禁用滚动和用户交互,您仍然可以显示某个位置,甚至显示用户位置:例如,查看kinetic应用程序。 – rdesign