2013-03-02 66 views
3

在關閉表編輯模式後,我仍然有一個editingAccessoryVieweditingAccessoryView問題。表編輯完成後,UISwitch在UITableViewCell中仍然可以略微顯示

當前我正在使用UISwitch作爲編輯配件視圖,並讓表視圖句柄在按下導航欄的編輯按鈕時通過動畫移動編輯視圖的開啓/關閉屏幕。

幾乎所有的編輯配件都可以在屏幕外正確顯示動畫,但總是有兩個不能使其脫離屏幕,然後在單元出列並重新使用時重用它們,以便在滾動過程中顯示它們。

有沒有其他人看到這個或有什麼我在這裏失蹤?

我設立這樣的細胞:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    AllStatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AllStatCell"]; 

    if (cell.editingAccessoryView == nil) { 
     UISwitch *statSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; 
     [statSwitch addTarget:self action:@selector(saveSwitchState:) forControlEvents:UIControlEventValueChanged]; 
     cell.editingAccessoryView = statSwitch; 
    } 

    NSString *statName = [self statNameForIndexPath:indexPath]; 
    cell.statName.text = statName; 
    [(UISwitch *)cell.editingAccessoryView setOn:[self switchValueForIndexPath:indexPath withStatNamed:statName]]; 

    if (tableView.editing) cell.statValue.hidden = YES; 

    return cell; 
} 

我試圖重寫setEditing方法的延遲之後重新加載表數據以允許動畫來完成,但它僅適用有時候

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 

    // Insert/delete the stat rows depending on editing mode 
    [self rebuildTableDataAnimated:YES]; 

    double delayInSeconds = 0.5; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     // Trying to fix bug that shows part of a UISwitch on screen still even though editing mode is completed 
     [self.tableView reloadData]; 
    }); 
} 

這裏有一個截屏:

Bug image

+0

我的第一次嘗試是在執行編輯之後重新加載表格。 – 2013-03-02 14:47:22

+0

@flexaddicted不幸的是,沒有工作 – iwasrobbed 2013-03-02 15:19:04

+0

對不起,我沒有看到它。如何重新加載它像'[tableView setEditing:NO animated:YES]; [tableView reloadData];'?你在後臺執行一些計算嗎? – 2013-03-02 15:28:45

回答

0

這感覺就像這樣一個黑客,所以希望別人有一個更好的解決辦法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    AllStatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AllStatCell"]; 

    NSString *statName = [self statNameForIndexPath:indexPath]; 

    // Hack fix for a bug that shows part of a UISwitch on screen still even though editing mode is completed 
    // Configure stat on/off switches 
    cell.editingAccessoryView = [self cellEditingAccessoryViewForEditing:tableView.editing]; 
    if (tableView.editing) [(UISwitch *)cell.editingAccessoryView setOn:[self switchValueForIndexPath:indexPath withStatNamed:statName]]; 

    cell.statName.text = statName; 
    [cell.statValue setHidden:tableView.editing]; 

    return cell; 
} 

// Hack fix for a bug that shows part of a UISwitch on screen still even though editing mode is completed 
- (UISwitch *)cellEditingAccessoryViewForEditing:(BOOL)tableIsEditing 
{ 
    if (tableIsEditing) { 
     UISwitch *statSwitch = [[UISwitch alloc] initWithFrame:CGRectZero]; 
     [statSwitch addTarget:self action:@selector(saveSwitchState:) forControlEvents:UIControlEventValueChanged]; 
     return statSwitch; 
    } 
    return nil; 
} 
1

舊線,但有UIStepper其在Xcode 7同樣的問題。我的解決方案是將其嵌入到左側和右側有一些填充的UIView中,然後將父視圖設置爲editingAccessoryView。它的工作原理,並不是一個破解。

相關問題