objective-c - cocoa-如何使用tableViewSelectionDidChange :?

标签 objective-c cocoa delegates nstableview

我的 View 中有一个NSTableview,当用户选择特定的时,我想执行一些其他操作。我尝试了 tableViewSelectionDidChange 方法,但它似乎不起作用。

-(void)tableViewSelectionDidChange:(NSNotification *)notification
{
    NSInteger row = [self.InfoTable selectedRow];

    if (row == -1) {
        return;
    }else{
        self.NumberInputTextField.stringValue = studentsInTable[row][0];
        self.NameInputTextField.stringValue = studentsInTable[row][1];
        self.ClassnumberInputTextField.stringValue = studentsInTable[row][1];
    }
}

我有

@interface ViewController : NSViewController <NSTableViewDelegate,NSTableViewDataSource>

self.InfoTable.dataSource = self;
self.InfoTable.dataSource = self;

另外,我用谷歌搜索过,但没有找到有用的答案。 谁能给我一点提示吗?

最佳答案

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification 是委托(delegate)方法,但您仅将 dataSource 设置为 self。

[self.InfoTable setDelegate:self];

关于objective-c - cocoa-如何使用tableViewSelectionDidChange :?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389155/

相关文章:

c# - 将 Action 和 Func 结合在一个参数中

iphone - 更新导航栏

ios - 如何在 ios 中逐行设计自定义单元格?

ios - Unity 窗口 + 原生 iOS 窗口在同一个 App 上?

iphone - 委托(delegate)不工作

iphone - 竞争条件与否?委托(delegate)和多线程

iphone - 在 Objective-C 中将 BOOL 转换为 id

iphone - 转身从类方法分配属性

objective-c - 如何防止 NSWindow 在 windowWillClose 方法上关闭?

objective-c - 如何从compileAndReturnError 获取错误消息?