NSSCrollView不会在NSALERT上滚动为附件



是否可以在nsalert上使用nsscrollview作为附件?

我想提示用户,并向他们显示图像列表,作为提示的一部分。

我的想法是显示一个包含图像的NSSCrollView,但是当ScrollView作为NSALERT表的一部分出现时,它会像内容一样出现,但是您不能滚动它。

>

我尚不清楚我是否缺少NSSCrollview设置上的一些简单步骤,还是仅仅是对NSALERT的约束。

任何帮助将不胜感激。

这是所讨论的代码:

NSAlert *alert = [NSAlert alertWithMessageText:prompt
                                 defaultButton:defaultButtonText
                               alternateButton:altButtonText
                                   otherButton:nil
                     informativeTextWithFormat:@"%@",infoText];
// create the scrollview
NSScrollView* scrollview = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 250, imageHeight)];
// fill the scrollview with images
int i = 0;
for (NSImage* image in images)
{
    // create a new image view
    NSImageView*  imageView = [[NSImageView alloc] initWithFrame:NSMakeRect(i*150, 5, 145, 145)];
    [imageView setImage:image];
    // add the subview to the content view and increase size of contents
    [scrollview.contentView addSubview:imageView];
    [scrollview.contentView setFrame: NSMakeRect(0,0,(i+1)*150, 155) ];
    // increment image counter
    i++;
}
// add the scrollview to the alert sheet
[alert setAccessoryView:scrollview];
// show the alert sheet
NSWindow* win = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
[alert beginSheetModalForWindow:win
                  modalDelegate:delegate
                 didEndSelector:endselector
                    contextInfo:nil];

我想您想将图像视图添加到滚动视图的文档视图中,而不是其内容视图。

最新更新