2011-11-02 120 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

我有同樣的問題,如果你有任何更多的代碼,請發送。 –

相關問題