发生排序时取消选择表列

时间:2015-02-06 13:18:38

标签: objective-c cocoa

我有一个应用程序,在单击按钮时加载表,当前用于表的排序选项已被删除,但是当我单击任何列然后单击表标题时,所选列应取消选中。不知道如何实现这一目标。

先谢谢!!!!

1 个答案:

答案 0 :(得分:1)

你必须触发' buttonSelected:'方法:)

 @interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) NSIndexPath *currentSelectedIndexPath;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

#pragma mark - UIViewControllerDelegate

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.currentSelectedIndexPath = nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.currentSelectedIndexPath = indexPath;
}

- (IBAction)buttonSelected:(UIButton *)sender {
    [self.tableView deselectRowAtIndexPath:self.currentSelectedIndexPath animated:YES];
}

@end