如何在单独的NIB中放置一个窗口,给它自己的NSWindowController,让它作为一张纸滑出?
(这是与床单有关的典型事吗?)
我试图从我的主窗口显示一个自定义工作表(从父窗口的标题栏向下滑动的窗口).我想,我想要做的就是标准,但是我找不到明确的例子或解释如何做到我想要的.
我想做什么:
- (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) 我试图将一个归因字符串放在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,它就可以正常工作.请帮忙!
好的,这是我的情况:
NSMutableArray绑定到NSTableView,通过NSArrayController.NSArrayController's selectNext:和selectPrevious:问题是:选择确实发生了变化,但表视图不会滚动到当前选择,因此其内容是可见的.
我该怎么办?有任何想法吗?
我试图读取传感器并将其显示为百分比.[某些值]将始终介于0和1之间.
这是我的代码:
NSNumber *reading = [some value];
reading = [reading floatValue] * 100;
Run Code Online (Sandbox Code Playgroud)
但是,我得到"从不兼容的类型float分配给NSNumber*_strong"
我是新工作的NSNumber对象,并且很难理解如何以用户的百分比显示我的传感器读数.例如:75%
谢谢你的帮助
我正在尝试将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消息).纸张永远不会挂在窗户上.
如果有人能指出我可以找到更多信息的地方,那将非常感激.
如何在自定义代码段中添加日期时间?
我需要经常使用我的代码添加到其他代码,而对于其他代码,我需要添加我的名字和日期时间.
我创建了一个带有快捷方式_ase的代码片段,但是我没有在网上找到任何帮助,我该如何为它添加时间.

我有一个包含一些元素的NSArrayController.这些元素有一些属性,如"名称","信息"等.
我想要的只是在NSArrayController中找到一个名称属性设置为的元素,比方说,'Mads'.
由于效率不是一个很大的问题,我只需要通过迭代NSArrayController中的所有元素进行线性搜索,同时检查'name'属性是否为'Mads'.
但我似乎无法从NSArrayController获得NSIterator,所以我想知道是否还有另一种方法可以做到这一点?
任何帮助表示赞赏
我有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)
执行此方法后,我看到没有标题栏的模态窗口,它看起来不像普通表.它只出现在第一个窗口的左下角.
你能帮帮我吗,我做错了什么?
鉴于字体,约束和文本,我只想知道行数.我可以在没有创建的情况下搞清楚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) 我已经浏览了这些SO帖子:
我尝试完全相同(多次重新检查),但我无法在我的Mac App中添加自定义字体.
所有细节都显示在附图中.
Plist已更新:(经过尝试的字体和字体/两者)
在App Bundle中,它位于Fonts文件夹路径中:

但我的代码无法找到并读取字体:

任何帮助/指出我的错误都非常感谢.
cocoa ×8
objective-c ×8
macos ×6
cocoa-sheet ×3
ios ×2
iphone ×2
nswindow ×2
nsalert ×1
nsfont ×1
nsnumber ×1
nsstring ×1
nstableview ×1
xcode ×1
xcode4.6 ×1