2013-10-15 4 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

он срабатывает при касании УДАЛИТЬ кнопку, а не минус ... И удалять кнопки на 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, а также определение метода для @selector (Done :) – Nick

+0

обновил мой ответ. – onivi