2012-11-03 53 views
0

我正在刪除具有UIImage視圖的UITableView中的單元格。當我滑動刪除UIView後面的刪除按鈕時,如果UIView位於刪除按鈕後面,它看起來會更好。有沒有一種方法可以將按鈕的圖層首選項設置爲頂層?在UITableView後面的自定義UIView中刪除按鈕的問題

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 

    [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 



    //Deletes view from cell 
    for (UIView *subview in [self.view subviews]) { 

     if (subview != self.tableView) { 
      [subview removeFromSuperview]; 
     } 
    } 

    NSError *error = nil; 
    if (![context save:&error]) { 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 
} 
[self performFetch]; 


} 
+0

你寫的代碼如何?你想隱藏你的UIImageView? – sunkehappy

+0

我不確定隱藏它,但我希望刪除按鈕位於頂部。我想隱藏按鈕後面的內容是可以的,但如果用戶決定不刪除,則需要取消隱藏。 – sonicbabbler

回答

0

我想你已經把你的子視圖(包括您的UIImageView)直接在單元格中,而不是內容查看的子視圖。

嘗試將它們添加到contentView中。

您是否繼承了您的單元格,並在init方法中添加了視圖?然後使用:

[[self contentView] addSubview:myImageView]; 

你沒有繼承的單元格,沒有你在的ViewController加入的UIImageView?

[[cell contentView] addSubview:myImageView]; 

這將導致內容查看包括圖像顯示在deletebutton時收縮。

如果你真的想把它放在按鈕的後面,試着將它移到某處。

[self sendSubviewToBack:myImageView];