代码问题 - 初学者
好的,到目前为止,这是我的代码:
@implementation PtyView
- (id)initWithFrame:(NSRect)frame;
{
if (self = [super initWithFrame: frame])
{
[self setFont:[NSFont fontWithName:@"Courier" size:0.0]];
[self startTask];
}
return self;
}
- (void)keyDown:(NSEvent *)event
{
const char * typein = [[event characters] UTF8String];
[masterHandle
writeData:[NSData dataWithBytes:typein length:strlen(typein)]];
}
...
@end
问题是我想从另一个实现触发“startTask”,但是,如果我只是“startTask”,它不会显示输出,因为我没有使用 initWithFrame。
我该怎么做?
谢谢, 以利亚
Ok here is my code so far:
@implementation PtyView
- (id)initWithFrame:(NSRect)frame;
{
if (self = [super initWithFrame: frame])
{
[self setFont:[NSFont fontWithName:@"Courier" size:0.0]];
[self startTask];
}
return self;
}
- (void)keyDown:(NSEvent *)event
{
const char * typein = [[event characters] UTF8String];
[masterHandle
writeData:[NSData dataWithBytes:typein length:strlen(typein)]];
}
...
@end
the problem is that I want to trigger "startTask" from another implementation but, if I just "startTask" it won't display the output because I didn't use initWithFrame.
How would I do this?
Thanks,
Elijah
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想从其他地方调用 startTask 而不首先创建 PtyView 实例,那么 startTask 必须是静态方法,而不是实例方法。
将其放入您的@interface中:
将其放入您的@implementation中
当您要调用它时将其放入:
注意:
+ 表示它是静态方法。
您无法从静态方法访问实例变量。
If you want to call startTask from somewhere else without first creating an instance of PtyView then startTask must be a static method, not an instance method.
Put this in your @interface:
Put this in your @implementation
Put this when you want to call it:
Notes:
The + means it's a static method.
You cannot access instance variables from a static method.
好吧,我认为,您正在为您的 PseudoTTY.app(版本)寻找 AMShellWrapperTest.app 中类似“执行”按钮的内容( http://amath.colorado.edu/pub/mac/programs/PseudoTTY.zip )。正确的?
Well, I think, you are looking for something like the "Execute" button in AMShellWrapperTest.app for your (version of) PseudoTTY.app ( http://amath.colorado.edu/pub/mac/programs/PseudoTTY.zip ). Right?