簡體   English   中英

UITableView編輯模式不起作用

[英]UITableView edit mode not working

我正在嘗試激活UITableView的編輯模式。 當我點擊“編輯”按鈕時,它會變為“完成”,但圓形的紅色減號不會顯示在表格中。 我發布了下面的一些方法。 應用程序委托創建了一個選項卡欄,選項卡內的視圖具有導航控制器。 一切都是在代碼中完成的,很少用nib文件完成。 怎么了?

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

繼承對它沒有任何影響。

當您將navigationController的右按鈕分配給它時,您可以使用此方法。

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

或者你可以編寫一個基本上切換UITableView狀態的方法

[tableView setEditing:TRUE];

當按鈕完成后,將其切換為

[tableView setEditing:FALSE];

您沒有正確繼承。

你不會從UIViewController中獲取任何東西,它只包含視圖。 我建議你嘗試UITableViewController。

你在哪里編寫另一種合適的視圖編輯方法就像這樣

-(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];
    }
}

固定! 不得不從UITableViewController繼承而不是UIViewController。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM