2013-10-15 90 views
8

我有一個UITableView,我想在編輯模式處於活動狀態時刪除一行,但未觸發commitEditingStyle。commitEditingStyle沒有被觸發

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 

    cell.text=[NSString stringWithFormat:@"Row Number %d",indexPath.row]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"trying to delete a row.."); 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 6; 
} 

-(void)Edit:(id)sender //Active editing mode 
{ 
    [self.table setEditing:YES animated:YES]; 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)]; 
} 

我只想刪除一行?

這是我怎麼顯示我酥料餅:

UIPopoverController *popover; 
-(IBAction)open:(id)sender 
{ 
    CGRect r=((UIButton*)sender).frame; 
    CGRect tRect=[((UIButton*)sender) convertRect:((UIButton*)sender).frame toView:self.view]; 
    tRect.origin.x=r.origin.x; 

    Popover *firstViewCtrl = [[Popover alloc] init]; 

    UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:firstViewCtrl]; 
    navbar.preferredContentSize = CGSizeMake(300, 300); 
    popover = [[UIPopoverController alloc] initWithContentViewController:navbar]; 
    popover.delegate = self; 
    popover.popoverContentSize = CGSizeMake(300, 300); 

    CGRect popRect = CGRectMake(0, 
           0, 
           200, 
           200); 

    [popover presentPopoverFromRect:popRect 
    inView:self.view 
    permittedArrowDirections:UIPopoverArrowDirectionAny 
    animated:YES]; 

    // [popover presentPopoverFromRect:tRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 
} 

我創建的UITableView使用Xcode的接口。

-(void)Done:(id)sender 
{ 
    [self.table setEditing:NO animated:NO]; 
    //[self.table endEditing:true]; 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(Edit:)]; 
} 

enter image description here

回答

8

它,當你觸摸DELETE按鈕,而不是減...和刪除您的tableview的按鈕不propably顯示,由於您的tableview的寬度火災...

0

編輯:看你的代碼後,我覺得charty是正確的。

務必檢查編輯風格,並對數據源進行必要的調整。是這樣的:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     NSLog(@"deleting"); 
     [_resultsArray removeObjectAtIndex:indexPath.row]; 
     [tableView reloadData]; 
    } 
} 
+0

沒有,我沒有忘記..我設置它.. – onivi

+0

請顯示你用來創建和代表UITableView和UIPopover,以及@選擇器(做完:) – Nick

+0

更新我的答案的方法定義的代碼。 – onivi