开发者

Sharing variables - objective-c

Here is 开发者_如何学编程my code:

PtyView *v = [[PtyView alloc] init];
[v sendData([charlieImputText stringValue])];

in the PtyView.m file I have this:

void sendData(NSString *data) {
NSRunAlertPanel(@"",data,@"",@"",@""); //used for testing
}

But for some reason, the code errors: saying that PtyView may not respond to sendData, and I know that the code is incorrect. How would I accomplish this?

Thanks!


sendData is not written in objective-C; it is a C primitive function. You should write a method in Obj-C like:

- (void) sendData: (NSString *)data {
  NSRunAlertPanel(@"",data,@"",@"",@"");
}


To add to what Anders has said, even if sendData were properly implemented as a method, it is not being called correctly. The correct invocation syntax would be

[v sendData: [charlieImputText stringValue]];

More information about Objective-C methods can be found in Apple's documentation.


make sure you are importing "PtyView.h" into the file you are using it in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜