代码问题 - 初学者

发布于 2024-09-25 18:46:38 字数 587 浏览 1 评论 0原文

好的,到目前为止,这是我的代码:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎盛开的樱花 2024-10-02 18:46:38

如果您想从其他地方调用 startTask 而不首先创建 PtyView 实例,那么 startTask 必须是静态方法,而不是实例方法。

将其放入您的@interface中:

+ (void)startTask;

将其放入您的@implementation中

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

当您要调用它时将其放入:

[PtyView startTask];

注意:
+ 表示它是静态方法。
您无法从静态方法访问实例变量。

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.

牵强ㄟ 2024-10-02 18:46:38

好吧,我认为,您正在为您的 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文