删除单元格 - UITableviewController

时间:2014-05-05 13:46:53

标签: ios objective-c uitableview

我用所有方法实施了UITableviewUITableviewController是初始视图控制器时,它可以正常工作,我可以滑动删除。

但是当UITableViewController是我项目的一部分并通过推送视图到达时,我无法滑动删除。似乎应用程序并不总是检测到滑动或类似的东西,因为有时会出现删除按钮。

这是一个非常简单的项目,没有大的操作。

(我使用Google Analytics和Google Adsense库,但不在此视图控制器中。)

---

编辑:有些代码和问题,上一个屏幕的代码可能会影响uitableviewcontroller的性能吗?

我的故事板是这样的:

[导航控制器] - > [Root View Controller] - > [表视图控制器]

代码:

VerreTableViewController.h

@interface VerreTableViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *table_view_verres;

@end

VerreTableViewController.m

@interface VerreTableViewController ()

@end

NSArray *objects_verres;

@implementation VerreTableViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    objects_verres = [Verre allWithOrder:@{@"date_prise" : @"DESC"}];
    _table_view_verres.delegate = self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return objects_verres.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [_table_view_verres dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    UILabel *lbl_nom = (UILabel *)[cell viewWithTag:10];
    UILabel *lbl_date = (UILabel *)[cell viewWithTag:11];

    NSManagedObject *matches = objects_verres[indexPath.row];

    lbl_nom.text = [matches valueForKey:@"nom_alcool"];
    lbl_date.text = [[matches valueForKey:@"date_prise"] formattedDateWithFormat:@"HH:mm - dd/MM/yyyy"];

    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath        
{

    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //code to delete
    }
}

1 个答案:

答案 0 :(得分:0)

我会指出你的帖子:Swipe to Delete not working

确保您实现了所有必要的方法,并且您没有在应用程序委托上运行异常的视图层次结构/代码。

我依稀记得嵌入在视图控制器中的故事板和tableview控制器的问题。也许其他人可以对此有所了解。