2011-09-26 22 views
0

我正在使用自定義單元格並添加tableview編程。我正在嘗試在我的應用程序中實施輕掃功能。當我嘗試滑動時,不會調用tableview數據源方法。刷卡刪除不適用於自定義單元格

tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain]; 
tableview.delegate=self; 
tableview.dataSource=self; 


tableview.backgroundColor=[UIColor clearColor]; 
tableview.backgroundColor=selectedBackGroundColor; 
tableview.separatorColor = [UIColor clearColor]; 


tableview.editing=YES; 
NSLog(@"%f %f",self.view.frame.size.width,self.view.frame.size.height); 
[self.view addSubview:tableview]; 

這種方法,即使細胞也沒有選擇......我失去了任何事情的代碼,請幫我出後調用

-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
    return UITableViewCellEditingStyleDelete; 
} 

+0

添加了一個子?您是否已將視圖添加到內容視圖?您的視圖是否會自動調整爲父級? – rckoenes

+0

是的,我在我的自定義內容視圖中添加了一個標籤和一個圖片。 – Srinivas

+0

我評論了所有標籤,我在自定義cell.even中添加了相同內容。如果我刷卡然後didselectRow ForIndexpath也沒有調用... – Srinivas

回答

8
-(void)layoutSubviews 
{ 
    [super layoutSubviews]; 
} 

那麼它的做工精細.....謝謝回答我的問題

+0

這是我刷卡刪除不工作的原因....我一直敲牆頭數週我的頭...非常感謝 –

+0

超... 。奇蹟般有效!!! –

1

您是否在數據源中實施了-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

0

使用此實現,而不是:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
     // Delete an object 
    } 
} 
1

如果你已經設置的tableview到editing已經我懷疑,滑動刪除(和選擇,如果allowsSelectionDuringEditingNO)將在所有的工作。嘗試刪除此行:

tableview.editing=YES; 

並查看是否啓用了滑動。

相關問題