2011-11-02 98 views
3

我已经创建了UITableViewCell的子类并添加了一个MapView。每当我滚动屏幕的地图并回滚到它再次加载的单元格时。 (正如你们都知道这是细胞重复使用的默认行为)防止在UITableViewCell里重新加载MKMapView

有没有办法阻止?或者你知道这种情况下的其他技巧吗?非常感谢!

+0

有多少个细胞..?单个或多个地图。 – aahsanali

+0

单元格中的地图很奇怪,用户如何滚动tableview? – jbat100

+0

有2到10个单元格。单元格中的地图根本不奇怪。如果您禁用滚动和用户交互,您仍然可以显示某个位置,甚至显示用户位置:例如,查看kinetic应用程序。 – rdesign

回答

4

一个可能的解决方案:

- (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如果是有意义的,你的应用程序。

+0

上面显示的关键是不要为该行使用可重用的单元格。 – ader

+0

我认为要走的路是定义这个独特的UITableCell的类中的所有东西,并设置在cellForRowAtIndexPath – carbonr

+0

我有同样的问题,如果你有任何更多的代码,请发送。 –