Objective c 从另一个类调用方法-NSTextView未加载数据
我有三门课: LocalRoom.mObjective c 从另一个类调用方法-NSTextView未加载数据,objective-c,cocoa,Objective C,Cocoa,我有三门课: LocalRoom.m - (void) handleNewConnection:(Connection*)connection { NSString* number = @"10"; AppDelegate *theAppDelegate = [[NSApplication sharedApplication] delegate]; [theAppDelegate connectionNumber:number currentZoneName:@"Zone
- (void) handleNewConnection:(Connection*)connection {
NSString* number = @"10";
AppDelegate *theAppDelegate = [[NSApplication sharedApplication] delegate];
[theAppDelegate connectionNumber:number currentZoneName:@"Zone1";
}
触发器------>
AppDelegate.h
MyTableController *tableController;
AppDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
tableController = [[MyTableController alloc] init];
}
- (void)connectionNumber:(NSString *)number zoneName:(NSString *)currentZoneName {
if ([currentZoneName isEqualToString:zoneName1]) {
[tableController changeConnections:number withRowNumber:0];
}
}
触发器------>
MyTableController.h
@interface MyTableController : NSControl {
IBOutlet NSTextField *zoneNameTextField;
}
@property (retain) NSTableView * idTableView;
- (void) changeConnections:(NSString *)number withRowNumber:(int)rowNumber;
MyTableController.m
- (void) changeConnections:(NSString *) number withRowNumber:(int) rowNumber{
NSRunAlertPanel([NSString stringWithFormat:@"%d", rowNumber], number, @"", @"", @"");
NSTableColumn *tableColumn = [[NSTableColumn alloc] initWithIdentifier: @"Connections"];
[self tableView:idTableView setObjectValue:number forTableColumn:tableColumn row:rowNumber];
[idTableView reloadData];
}
我的NSRunAlertPanel提供了正确的值,但我的NSTextView没有更改。当我将NSTableView的“编辑”代码放在MyTableController.m的iAction中时,它就工作了。我检查了idTableView是否为空,它是否为空。这很奇怪。因此,当AppDelegate运行changeConnections时,我有一种奇怪的感觉。我有一个类似的问题,nstextfield没有返回数据。修复方法是通过AppDelegate*theAppDelegate=[[NSApplication-sharedApplication]delegate]初始化它代码>在这种情况下是否存在类似情况
您可能想知道为什么我不从LocalRoom调用MyTableController,而是在应用程序委托中设置并找到了“zoneName1”
提前谢谢 您尚未显示所有代码,但是idTableView
被声明为MyTableController
的@属性,但不是IBOutlet
也就是说,idTableView
为NULL强烈表明,idTableView
属性从未设置为适当的表视图。无IBOutlet
,因为它意味着无法在NIB/XIB中连接。因此,修复方法可能是将其作为一个插座,并将其连接到NIB中
显然,如果idTableView
为空,[idTableView reloadData]
则无效
我假设您的NIB将MyTableController
设置为其表数据委托,这就是直接编辑可以工作的原因
此外,尽管我认为这与您的问题无关,但为了获得最佳实践,创建一个新的NSTableColumn
来处理您现有的表是没有意义的——您应该使用[idTableView tableColumnWithIdentifier:@“Connections”]
。嘿!对不起,我没有包括在内。但是“ibnstableview idTableView;”有。奇怪的是为什么它仍然返回空值。我在myTableController的init中放了相同的代码,它可以工作。handleNewConnection:在什么时候被调用?在没有看到这种逻辑的情况下,我想知道它是否发生在加载nib之前。。。我的工作假设您的[MyTableController init]正在调用[super initWithNibName:@“some nib”bundle:nilOrSomeBundle]。