gpt4 book ai didi

iphone - 删除分组 TableView 中的一行

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:31 27 4
gpt4 key购买 nike

嗯,有些不对劲,但我不知道是什么。我无法删除一行。当我的 tableview 进入编辑模式时,所有行附近都会出现红色减号。触摸它们使行上出现删除按钮,当我触摸它时它变成(深红色)并且没有任何反应。

这是我的代码(不是全部)+我在编译和运行时没有错误和警告......

- (void)viewDidLoad {

[super viewDidLoad];

// initialize singleton.
appDelegate = (ExchangedAppDelegate *)[[UIApplication sharedApplication]delegate];

// get banks from settings.plist
NSString *tempPath = [self getPathOfSettingsPlist];

appDelegate.banks = [[NSArray alloc]initWithContentsOfFile:tempPath];

navigationItem.rightBarButtonItem = self.editButtonItem;

backButton = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonSystemItemCancel target:self action:@selector(closeSettingsView)];

navigationItem.leftBarButtonItem = backButton;

}


- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

[super setEditing:editing animated:animated];

[banksTableView setEditing:editing animated:animated];

if (editing) {

addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addBankFromList)];

navigationItem.leftBarButtonItem = addButton;

} else {


navigationItem.leftBarButtonItem = backButton;

NSString *tempPath = [self getPathOfSettingsPlist];

self.picker.hidden = YES;

[appDelegate.banks writeToFile:tempPath atomically:YES];
}

}



- (void)addBankFromList {

// not interesting

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [appDelegate.banks count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"BanksTableCell";

indexForPath = indexPath;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

cell.selectionStyle = UITableViewCellEditingStyleNone;
}

cell.textLabel.text = [appDelegate.banks objectAtIndex:indexPath.row];

return cell;
}


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

if (editingStyle == UITableViewCellEditingStyleDelete) {

// Delete the row from the data source
[appDelegate.banks removeObjectAtIndex:indexPath.row];

[banksTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

[banksTableView reloadData];
}
}

//// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSString *temp = [appDelegate.banks objectAtIndex:fromIndexPath.row];
[appDelegate.banks removeObjectAtIndex:fromIndexPath.row];
[appDelegate.banks insertObject:temp atIndex:toIndexPath.row];
}

最佳答案

实际上您在commitEditingStyle: 方法名称中添加了一个额外的冒号(":")。添加额外的冒号使该方法成为一种完全不同的方法。因此,您的 View Controller 认为您没有实现 commitEditingStyle: 方法,并且在您编辑 TableView 时没有执行任何操作。

只需删除 commitEditingStyle: 方法中 editingStyle 之后的冒号(":")。这将解决问题。该行应如下所示,

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

关于iphone - 删除分组 TableView 中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6506228/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com