简体   繁体   English

UITableView编辑模式不起作用

[英]UITableView edit mode not working

I'm trying to activate the edit mode for a UITableView. 我正在尝试激活UITableView的编辑模式。 When I click the "Edit" button, it changes to "Done" but the round red minus signs dont show up in the table. 当我点击“编辑”按钮时,它会变为“完成”,但圆形的红色减号不会显示在表格中。 I'm posting below some of the methods of the class. 我发布了下面的一些方法。 The app delegate created a Tab Bar and the views inside the tabs have navigation controllers. 应用程序委托创建了一个选项卡栏,选项卡内的视图具有导航控制器。 all is done in code, little is done with nib files. 一切都是在代码中完成的,很少用nib文件完成。 What's wrong? 怎么了?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
    return [ikub.subscriptions count];  
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
    int i = [indexPath row];  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];  
    if (cell == nil) {  
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];  
    }  
    Subscriptions *s = [ikub.subscriptions objectAtIndex:i];  
    cell.textLabel.text         = [s title];  
    cell.detailTextLabel.text   = [NSString stringWithFormat:@"%@ artikuj te rinj, %@ artikujt te lexuar", [s new], [s read]];  
    if (deleteActive) {  
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;  
    } else {  
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
    }  
    return cell;  
}  
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
    Subscriptions *s = [ikub.subscriptions objectAtIndex:[indexPath row]];  
        NSString *address = [[NSString alloc] init];  
        NSString *type = [NSString stringWithString:[s type]];  
        if ([type isEqualToString:@"Category"]) {  
            address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?node=9e26cdb8-dba6-4504-8bb6-29f0753be179~%@", [s code]];  
        } else if ([type isEqualToString:@"Tag"]) {  
            address = [NSString stringWithFormat:@"http://www.ikub.al/Rss.aspx?tag=%@", [s code]];  
        }
        address = [address stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];  
        SubscriptionStories *ss = [[SubscriptionStories alloc] init];  
        ss.address = address;  
        ss.title = [s title];  
        [self.navigationController pushViewController:ss animated:YES];  
        [ss release];  
}  
- (void)viewWillAppear:(BOOL)animated {  
    [subscriptionsTable reloadData];  
}  
- (void)viewDidLoad {  
    refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:nil];  
    self.navigationItem.leftBarButtonItem = refreshButton;  
    [refreshButton release];  
    self.navigationItem.rightBarButtonItem = self.editButtonItem;  
    [super viewDidLoad];      
}  
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {    
    return YES;  
}

The inheritance don't have any impact on it. 继承对它没有任何影响。

You can use this method it works when you assign the rightbutton of the navigationController to it. 当您将navigationController的右按钮分配给它时,您可以使用此方法。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [tableView setEditing:editing animated:YES];
}

Or you can write a method which basically toggles the state of the UITableView like 或者你可以编写一个基本上切换UITableView状态的方法

[tableView setEditing:TRUE];

and when the button has become done then toggle it to 当按钮完成后,将其切换为

[tableView setEditing:FALSE];

You aren't inheriting correctly. 您没有正确继承。

You're not going to get anything out of the UIViewController, it only contains the views. 你不会从UIViewController中获取任何东西,它只包含视图。 I suggest you try UITableViewController. 我建议你尝试UITableViewController。

Where you write the other method of uitable view editing method Like this 你在哪里编写另一种合适的视图编辑方法就像这样

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        rowNumber = indexPath.row;
        UIActionSheet *registerActionSheet = [[UIActionSheet alloc] initWithTitle:@"Sure You Want To Delete?"delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Yes", nil];
        registerActionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
        [registerActionSheet showInView:self.view];
        [registerActionSheet release];
        // delete your data item here
        // Animate the deletion from the table.
        //[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

Fixed! 固定! Had to inherit from UITableViewController not UIViewController. 不得不从UITableViewController继承而不是UIViewController。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM