1

作为我正在开发的 Mac 应用程序的一部分,用户填写了一个满是内容的屏幕,然后按下“处理”按钮。执行了编辑,如果一切都通过了编辑,则会执行几分钟的过程,无论是否结束。我希望该进程将一系列状态和处理消息吐出到一个单独的滚动窗口中,以便如果出现问题,用户可以返回日志并查看是否有任何显示在那里。

什么是我审查和用于此类处理的最佳对象和方法?

添加于 2011 年 11 月 24 日

根据第一个建议,我创建了第二个 XIB,创建了一个 NSWindowController 来匹配并将它们放在一起作为一些准备工作。当在应用程序委托中按下按钮时,我让这件事执行以下操作:

- (IBAction)runButtonPressed:(id)sender {

RunResultWindow *wc;

wc = [[RunResultWindow alloc] initWithWindowNibName:@"RunResultWindow"];

[wc showWindow:self];

}

RunResultWindow 是 XIB 和控制它的 NSWindowController 类的名称。我还添加了一个完成按钮并将其连接起来,目的是让处理结果填满文本窗口,然后挂在那里,直到用户按下“完成”或“完成”或我最终调用该按钮的任何内容。

当我按下主窗口上的按钮时,它实际上显示了窗口,但是当按钮的代码完成时,窗口消失了。显然,我遗漏了(一个重要的)步骤。

一旦我得到窗口,我就可以添加文本视图等......并让它工作。我想要的是让新窗口获得焦点,然后在用户按下“完成”按钮时关闭。

此外,我从 window 方法(它返回一个地址)获得了窗口控制器的窗口,并在 NSWindowController 的 windowDidLoad 方法中尝试了几个窗口焦点方法,但没有骰子。

再次感谢我能得到的任何信息。

添加于 2011 年 11 月 25 日

呃。也许如果我将类实例设为 ivar 而不是将其嵌入到按钮方法中,它将起作用,而且,它确实如此。哎呀。

4

2 回答 2

1

听起来您想将NSTextView放到一个可以选择和滚动文本但不能编辑内容的窗口中。

insertText:您可以像使用该方法一样轻松地插入文本。

于 2011-11-21T02:37:06.950 回答
0

So... The NSTextView and insertText combination worked out somewhat ok but I don't' think it is the final answer. First, my understanding is that insertText is really only meant for user input and not background 'system' input to a NXTextStorage object. I'm not sure why but that's fine so I'll avoid it. There are other options. I did find the beginEdit and endEdit methods and it works pretty much about the same way though I have some more work to do on some detail delegate methods.

The part that doesn't work so well is getting the NSScrollView in the window to update on demand. I do the beginEdit and endEdit stuff and am able to update the NSTextStorage object properly. I can do this multiple times in the same method (a test button on the window containing the scroll view). I can tell that because print-object in debug shows me what I'm expecting at the right times. However, I'd like to be able to show an updated NSScrollView multiple times during the court of the windowDidLoad method. The scroll view updates properly when the button push method ends.

Here is some sample code. I do mix insertText and the begin/end edit methods in here but it was more of a test thing than any code I would use for real....

(IBAction)FinishButtonPush:(id)sender {

    NSString *teststring;
    teststring = [NSString stringWithString: @"show"];
    [RunResultWindowTextView setString:teststring];
    teststring = [NSString stringWithString: @"show show"];
    [RunResultWindowTextView setString:teststring];
    teststring = [NSString stringWithString: @"show show show show"];
    [RunResultWindowTextView setString:teststring];
    [RunResultWindowTextView insertText:@"123"];
    NSTextStorage *tempTextStorage;

    tempTextStorage = [RunResultWindowTextView textStorage];

    [tempTextStorage beginEditing];
    [tempTextStorage replaceCharactersInRange:NSMakeRange(5,13)
                            withString:@"Hello to you!"];
    [tempTextStorage endEditing];

    [tempTextStorage beginEditing];
    [tempTextStorage replaceCharactersInRange:NSMakeRange(10,13)
                            withString:@"second change"];
    [tempTextStorage endEditing];

    [RunResultWindowTextView insertText:@"xxx123"];
    [RunResultWindowTextView insertText:@"xxx123567"];
}

Even though the NSTextStorage object is updated properly, the scroll view only updates when the method completes. My understanding is that processEdit is called automatically during endEdit. I added processEdit in there just to see and all I got was either abends or no change depending on where I put the command.

This got deleted and I'm not sure why. If you're going to gong the post, please let me know why you did so. Can't improve my post unless I have an idea what was wrong with it....

于 2011-11-29T01:00:09.887 回答