开发者

Sharing variables - objective-c

开发者 https://www.devze.com 2023-01-19 16:40 出处:网络
Here is 开发者_如何学编程my code: PtyView *v = [[PtyView alloc] init]; [v sendData([charlieImputText stringValue])];

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

精彩评论

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

关注公众号