Как создать представление из xib? - PullRequest
1 голос
/ 26 января 2012

У меня есть представление в xib-файле, я хочу поместить это представление в окно .... Я использую этот код:

- (void) popupNotificationWithTag:(NSString *)tag fade:(double)msFade lineOne:(NSString *)lineOneText lineTwo:(NSString *)lineTwoText
{
    NotificationWindow *notificationWindow;
    NotificationWindow *tmpWindow;
    NSEnumerator *enumerator;

    // Walk the notification windows in the array
    enumerator = [self.notificationWindows objectEnumerator];
    if(enumerator)
    {
        while((tmpWindow = [enumerator nextObject]))
        {
            if([tmpWindow.tag isEqualToString:tag])
            {
                notificationWindow = tmpWindow;
            }
        }
    }

    // Make a new notification window
    if (!notificationWindow)
    {
        int width = [[NSScreen mainScreen] frame].size.width;
        int height = [[NSScreen mainScreen] frame].size.height;

        notificationWindow = [[NotificationWindow alloc] initWithRect:NSMakeRect(width - 420, height - 130, 400, 100)];
        NSNib *nib = [[NSNib alloc] initWithNibNamed:@"Notification" bundle: nil];
        NSArray *objects;
        [nib instantiateNibWithOwner:self topLevelObjects:&objects];
        [notificationWindow setContentView: [objects objectAtIndex:0]];

        [notificationWindow setTag:tag];         
        [self.notificationWindows addObject:notificationWindow];
    }

    // Display window
    [notificationWindow makeKeyAndOrderFront:nil];
    [notificationWindow display];
    notificationWindow.fadeOut = msFade;
    [notificationWindow setPrimaryText:lineOneText];
}

Представление - это единственное, что есть в xib-файле, поэтому я хотел бы, чтобы objectAtIndex:0 было бы в порядке, но я получил исключение -[NSApplication setFrame:]: unrecognized selector sent to instance 0x100508500 в этой строке.

Обновление Я заменил строку на этот блок кода:

    for (id obj in objects) {
        if ([[obj class] isSubclassOfClass:[NSView class]])
            [notificationWindow setContentView: obj];
    }

1 Ответ

1 голос
/ 26 января 2012

Я смутно припоминаю, что у перьев есть скрытый 1-й объект, который представляет первого респондента (или что-то).Вместо этого попробуйте objectAtIndex: 1 и посмотрите, работает ли это.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...