iphone - 防止在 UITableViewCell 内重新加载 MKMapView

标签 iphone cocoa-touch uitableview mkmapview

我创建了 UITableViewCell 的子类并添加了 MapView。每次我滚动屏幕 map 并滚动回该单元格时,它都会再次加载。 (众所周知,这是单元重用的默认行为)

有什么办法可以防止这种情况发生吗?或者你还知道针对这种情况的其他技巧吗?非常感谢!

最佳答案

一种可能的解决方案:

- (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 替换为实例变量。

关于iphone - 防止在 UITableViewCell 内重新加载 MKMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7987346/

相关文章:

iphone - 如何使添加到 UITableViewCell 内容 View 的 UIView 适合其范围?

iphone - 界面生成器锁定项目位置?

ios - 如何将 OTP 从用户的消息框直接填充到 iPhone 中的应用程序?

iphone - 崩溃使 NSPersistentStoreCoordinator 的 url 无效

ios - 添加新项目后 UITableView 未更新(使用核心数据)

iOS 7.0 UITableView backgroundView 内的控件禁用用户交互

iphone - UITableView 覆盖/隐藏图像?

ios - 如何快速提高 ClCircularRegion 中半径的精度?

objective-c - 从自定义 UITableViewCell 获取值

objective-c - 拉出 UI slider 名称