objective-c – 麻烦使用Cocoa的自定义模态表

objective-c – 麻烦使用Cocoa的自定义模态表,第1张

概述我的目标:当应用程序通过冗长的循环时,显示带有确定的NSProgressIndicator的自定义工作表.我希望工作表是应用程序模式,而不是文档模式.用户无法关闭模态表.他们必须等待应用程序完成循环处理. 问题:我无法将自定义工作表附加到窗口.它显示为缺少窗口标题栏的单独窗口(如表单所示).此外,当循环结束时,纸张不会释放(不会关闭). 我有两个单独的nib文件用于工作表和主应用程序窗口,还有两个 我的目标:当应用程序通过冗长的循环时,显示带有确定的nsprogressIndicator的自定义工作表.我希望工作表是应用程序模式,而不是文档模式.用户无法关闭模态表.他们必须等待应用程序完成循环处理.

问题:我无法将自定义工作表附加到窗口.它显示为缺少窗口标题栏的单独窗口(如表单所示).此外,当循环结束时,纸张不会释放(不会关闭).

我有两个单独的nib文件用于工作表和主应用程序窗口,还有两个控制器类用于每个窗口.

以下是相关信息:
自定义工作表的控制器实现:

@implementation ProgressSheetController //subclass of NSPanel-(voID)showProgressSheet:(NSWindow *)window{    //progresspanel is an IBOutlet to the NSPanel    if(!progresspanel)        [NSBundle loadNibnamed:@"Progresspanel" owner:self];    [NSApp beginSheet: progresspanel       modalForWindow: window        modalDelegate: nil       dIDEndSelector: nil          contextInfo: nil];    //modalSession is an instance variable    modalSession = [NSApp beginModalSessionForWindow:progresspanel];    [NSApp runModalSession:modalSession];}-(voID)removeProgressSheet{    [NSApp endModalSession:modalSession];    [NSApp endSheet:progresspanel];    [progresspanel orderOut:nil];}//some other methods @end

主应用程序窗口的实现. testfiles方法是一个连接到按钮的IBAction.

@implementation MainWindowVIEwController //subclass of NSObject-(IBAction)testfiles:(ID)sender;{    //filesToTest is a mutable array instance variable    int count = [filesToTest count];    float progressIncrement = 100.0 / count;    ProgressSheetController *modalProgressSheet = [[ProgressSheetController alloc] init];    [modalProgressSheet showProgressSheet:[NSApp mainWindow]];    int i,for(i=0; i<count; i++)    {        //do some stuff with the object at index i in the filesToTest array        //this method I dIDn't show in ProgressSheetController.m but I think it's self explanatory        [modalProgressSheet incrementProgressbarBy:progressIncrement];    }    //tear down the custom progress sheet    [modalProgressSheet removeProgressSheet];    [modalProgressSheet release];}@end

一想法:我是否正确地进行了分类?我应该使用NSWindowController吗?预先感谢您的帮助!

解决方法 发现 this gem做了一些谷歌搜索. Interface Builder中我的NSPanel的行为设置为“在启动时可见”,这是使用IB时新窗口的默认值.发生的事情是,一旦装入笔尖,窗口就会在[NSApp beginSheet:…]之前显示出来.因此,取消选中“在启动时可见”选项可以解决我的问题,现在一张工作表就像我想要的那样连接到窗口. 总结

以上是内存溢出为你收集整理的objective-c – 麻烦使用Cocoa的自定义模态表全部内容,希望文章能够帮你解决objective-c – 麻烦使用Cocoa的自定义模态表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1007553.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存