小编Ano*_*dya的帖子

如何从单独的NIB显示工作表

如何在单独的NIB中放置一个窗口,给它自己的NSWindowController,让它作为一张纸滑出?

(这是与床单有关的典型事吗?)

我试图从我的主窗口显示一个自定义工作表(从父窗口的标题栏向下滑动的窗口).我想,我想要做的就是标准,但是我找不到明确的例子或解释如何做到我想要的.

我想做什么:

  1. 我的app delegate拥有主窗口,该窗口有一个用于打开"设置"表的按钮.
  2. "设置"表:
    • 是在一个单独的NIB.
    • 将文件所有者设置为类SettingsWindowController,它是NSWindowsController的子类
  3. 当用户点击"设置"时,我试图使用Apple的[示例代码] [1]
- (void)showCustomSheet: (NSWindow *)window
// User has asked to see the custom display. Display it.
{
    if (!settingsSheet) 
    //Check the settingsSheet instance variable to make sure the custom sheet does not already exist.
        [NSBundle loadNibNamed:@"SettingsSheet" owner: self];
        //BUT HOW DOES THIS MAKE settingsSheet NOT nil?

    [NSApp beginSheet: settingsSheet
            modalForWindow: window 
            modalDelegate: self 
            didEndSelector: @selector(didEndSheet:returnCode:contextInfo:) 
            contextInfo: nil]; 

    // Sheet is up here.

    // Return processing to the event loop
} …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c interface-builder cocoa-sheet

8
推荐指数
1
解决办法
3338
查看次数

[__NSCFConstantString pointSize]:发送到instanc的无法识别的选择器

我试图将一个归因字符串放在NSTextField中,它本身就在NSAlert里面这是我的代码:

NSTextField *label1 = [[NSTextField alloc]initWithFrame:NSMakeRect(0, 23, 50, 20)];
[label1 setEditable:FALSE];
[label1 setAllowsEditingTextAttributes:TRUE];
[label1 setBezeled:FALSE];
label1.backgroundColor = [NSColor clearColor];
NSString *login = @"Username";
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:login];
NSString *boldFontName = [[NSFont boldSystemFontOfSize:12] fontName];
[attrString beginEditing];
NSRange ran = NSMakeRange(0, 8);
[attrString addAttribute:NSFontAttributeName
                   value:boldFontName
                   range:ran];

[attrString endEditing];
NSLog(@"%@",attrString);
[label1 setAttributedStringValue:attrString];
[alert setAccessoryView:label1];
[alert runModal];
Run Code Online (Sandbox Code Playgroud)

但是,一旦调出[alert runModal],我的应用程序就会崩溃

"[__NSCFConstantString pointSize]: unrecognized selector sent to instance 0x7fff74035bb0"
Run Code Online (Sandbox Code Playgroud)

我不确定为什么会这样.它似乎与字符串有关,因为只要我删除[alert setAccessoryView:label1]或给label1一个标准的nsstring,它就可以正常工作.请帮忙!

macos cocoa objective-c nsattributedstring nsalert

8
推荐指数
1
解决办法
6526
查看次数

滚动NSTableView以进行选择

好的,这是我的情况:

  • 我有一个NSMutableArray绑定到NSTableView,通过NSArrayController.
  • 我正在操纵表视图的选择(通过键盘触发),使用NSArrayController's selectNext:selectPrevious:

问题是:选择确实发生了变化,但表视图不会滚动到当前选择,因此其内容是可见的.

我该怎么办?有任何想法吗?

macos cocoa objective-c nstableview nsarraycontroller

8
推荐指数
1
解决办法
2949
查看次数

如何在NSNumber上做数学

我试图读取传感器并将其显示为百分比.[某些值]将始终介于0和1之间.

这是我的代码:

NSNumber *reading = [some value];
reading = [reading floatValue] * 100;
Run Code Online (Sandbox Code Playgroud)

但是,我得到"从不兼容的类型float分配给NSNumber*_strong"

我是新工作的NSNumber对象,并且很难理解如何以用户的百分比显示我的传感器读数.例如:75%

谢谢你的帮助

iphone cocoa objective-c nsnumber ios

8
推荐指数
2
解决办法
2万
查看次数

如何将NSPanel显示为工作表

我正在尝试将NSPanel显示为工作表.我天真地做着这样的事情:

SheetController *sheetController = [[[SheetController alloc]
                                      initWithWindowNibName:@"Sheet"] autorelease];

[[NSApplication sharedApplication] beginSheet:sheetController.window 
                               modalForWindow:self.window
                                modalDelegate:self
                               didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
                                  contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)

出于某些原因,我无法解决这个问题.当调用此部分代码时,工作表会暂时闪烁(因为autorelease消息).纸张永远不会挂在窗户上.

如果有人能指出我可以找到更多信息的地方,那将非常感激.

cocoa objective-c nswindow cocoa-sheet

7
推荐指数
1
解决办法
6571
查看次数

在XCode中的自定义/用户代码段中添加时间和日期

如何在自定义代码段中添加日期时间?

我需要经常使用我的代码添加到其他代码,而对于其他代码,我需要添加我的名字和日期时间.

我创建了一个带有快捷方式_ase的代码片段,但是我没有在网上找到任何帮助,我该如何为它添加时间.

在此输入图像描述

macos xcode objective-c code-snippets xcode4.6

7
推荐指数
1
解决办法
1296
查看次数

在NSArrayController中查找特定元素

我有一个包含一些元素的NSArrayController.这些元素有一些属性,如"名称","信息"等.

我想要的只是在NSArrayController中找到一个名称属性设置为的元素,比方说,'Mads'.

由于效率不是一个很大的问题,我只需要通过迭代NSArrayController中的所有元素进行线性搜索,同时检查'name'属性是否为'Mads'.

但我似乎无法从NSArrayController获得NSIterator,所以我想知道是否还有另一种方法可以做到这一点?

任何帮助表示赞赏

cocoa nsarraycontroller

6
推荐指数
2
解决办法
2240
查看次数

beginSheet方法对我不起作用

我有saveWindowController(NSWindowController子类对象).我使用initWithWindowNibName:方法来初始化控制器.
我在xib中设置了File的所有者SaveWindowController.我在xib文件中连接delegate(从窗口)到File的所有者和window(从控制器)到NSWindow.

[NSApp beginSheet:[self.saveWindowController window] 
   modalForWindow:[self window]
    modalDelegate:nil didEndSelector:nil contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)

执行此方法后,我看到没有标题栏的模态窗口,它看起来不像普通表.它只出现在第一个窗口的左下角.

你能帮帮我吗,我做错了什么?

macos cocoa nswindow cocoa-sheet

6
推荐指数
1
解决办法
1861
查看次数

我可以在不创建UILabel的情况下找出NSString的numberOfLines吗?

鉴于字体,约束和文本,我只想知道行数.我可以在没有创建的情况下搞清楚UILabel吗?

+ (int)numberOfLines:(NSDictionary *)data{
    NSString *myString = [some string calculation];
    CGSize sizeConstrain = CGSizeMake(some constrain calculation);
    CGSize stringSize = [myString sizeWithFont:someFont constrainedToSize:sizeConstrain];

    CGRect labelFrame = CGRectMake(0,
                                   0,
                                   stringSize.width,
                                   stringSize.height + 2);

    UILabel *label = [[UILabel alloc]initWithFrame:labelFrame];

    label.text = myString;
    return label.numberOfLines;
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsstring ios

6
推荐指数
0
解决办法
134
查看次数

无法在Mac应用程序中添加自定义字体(OSX 10.9+ Xcode5 +)

我已经浏览了这些SO帖子:

在mac包中嵌入字体

Cocoa应用程序中的自定义字体

我尝试完全相同(多次重新检查),但我无法在我的Mac App中添加自定义字体.

所有细节都显示在附图中.

Plist已更新:(经过尝试的字体和字体/两者) 在此输入图像描述 在App Bundle中,它位于Fonts文件夹路径中: 在此输入图像描述

但我的代码无法找到并读取字体: 在此输入图像描述

任何帮助/指出我的错误都非常感谢.

macos cocoa objective-c nsfont

6
推荐指数
1
解决办法
1773
查看次数