开发者

code problem - beginner

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 chara开发者_如何学编程cters] 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


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:

+ (void)startTask;

Put this in your @implementation

+ (void)startTask
{
    // Code goes here
}

Put this when you want to call it:

[PtyView startTask];

Notes: The + means it's a static method. You cannot access instance variables from a static method.


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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜