简体   繁体   English

NSTableView不刷新

[英]NSTableView not refreshing

I have a table view that gets refreshed two different ways. 我有一个可以通过两种不同方式刷新的表视图。 Both are through a button, and as a matter of fact, both are through the same IBAction in the same class! 两者都是通过按钮,实际上,都是通过同一类中的同一IBAction!

Here's my problem: 这是我的问题:

The buttons are in two different .xib files, the button in the same xib as the table view works perfectly, while the one in the different xib does the method to get the new data, but it DOES NOT refresh the table. 这些按钮位于两个不同的.xib文件中,与表视图相同的xib中的按钮可以正常工作,而不同xib中的一个按钮则可以使用这种方法来获取新数据,但不会刷新表。 Same exact method, different results. 完全相同的方法,不同的结果。 To get the IBAction for the other button I simply dragged out an NSObject in IB and set its class to the class of my table view, which contains the IBAction, then hooked it up to my button. 为了获得另一个按钮的IBAction,我只需在IB中拖出一个NSObject并将其类设置为包含IBAction的表视图的类,然后将其连接到我的按钮即可。

How can I fix this? 我怎样才能解决这个问题?

Sounds like you're creating a second, parallel, object of your class in the second XIB. 听起来您正在第二个XIB中创建您的类的第二个并行对象。 The button sends a message to that instance, which does some of the stuff you expect because it's an object of the right class, but it isn't actually the right object and isn't connected to your view. 该按钮会向该实例发送一条消息,该实例将执行您期望的某些操作,因为它是正确的类的对象,但是它实际上不是正确的对象,并且未连接到您的视图。

What you need to do is ensure that both buttons talk to the same instance. 您需要做的是确保两个按钮都与同一个实例对话。 This is easiest if the target is in the responder chain -- you should be able to set the button's target to First Responder and the message will find its way to the right place. 如果目标位于响应者链中,这是最容易的-您应该能够将按钮的目标设置为“ 第一响应者” ,并且消息将找到正确的位置。 Otherwise, you need to get a pointer to the target into the XIB, eg as an IBOutlet in the object that will be File's Owner . 否则,您需要在XIB中获得指向目标的指针,例如,作为将成为File Owner的对象中的IBOutlet。

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

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