2013-10-15 9 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]; 
} 

私はXcodeのインタフェースを使用してのUITableViewを作成しました:

これは私が私のポップオーバーを表示する方法です。

-(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

答えて

0

編集:あなたのコードを見た後、私はchartyが正しいことだと思います。

編集スタイルを確認して、データソースに必要な調整を加えてください。何かのように:あなたはがマイナス、ボタンをないDELETE ...そして、あなたのテーブルビューのボタンを削除するため、あなたのテーブルビューの幅にpropably表示されません触れたときに

-(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(完了)のメソッド定義を作成するために使用したコードを表示してください。 – Nick

+0

私の答えを更新しました。 – onivi

関連する問題