这可能是不可能的,但我希望有人会知道如何做到这一点.
我有一个应用程序,我只从iPhone移植到环球.在iPhone上,我使用的是Tabbed应用程序.我使用三个选项卡显示正常数据.我有一个第四个标签,只有在满足某些条件时才会显示.要添加选项卡,我会:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
UITabBarController *tabController = (UITabBarController *) self.rootViewController;
NSMutableArray* newArray = [NSMutableArray arrayWithArray: tabController.viewControllers];
[newArray addObject: [theStoryboard instantiateViewControllerWithIdentifier: @"AdditionalView-Phone"]];
[tabController setViewControllers:newArray animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
对于iPad,我在初始视图上有足够的空间来显示iPhone UI中主要三个选项卡的所有内容.所以我需要的是"附加"数据的另一个(小)视图.我想使用popOver视图来完成它,所以我使用Nav bar和popover按钮设置初始视图,就像在Utility App模板中一样.但是现在我被卡住了.我无法弄清楚如何在运行时创建弹出窗口按钮并使其正确执行popOver视图.我可以像这样添加按钮:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] initWithTitle: @"Modem" style: UIBarButtonItemStylePlain target: self action: @selector(togglePopover:)];
self.navBar.topItem.rightBarButtonItem = flipButton;
Run Code Online (Sandbox Code Playgroud)
但我得到一个例外:'NSInternalInconsistencyException',原因:'UIStoryboardPopoverSegue必须从一个条形按钮项或视图中显示.' 我很确定这是因为我没有为popOver segue设置锚点.故事板中不存在该按钮,因此我无法将其设置在那里.我似乎无法在运行时找到一个API来设置它.
我也尝试在IB中创建按钮,但不在视图层次结构中创建按钮,然后将rightBarButtonItem属性设置为现有按钮.这也有效,但我仍然无法将该按钮设置为弹出视图的锚点.我可以将导航栏设置为锚点,但这会使其锚定到导航栏中的标题,这看起来很傻.
有任何想法吗?
我认为这是第一个响应问题,但我不确定.我正在为表视图中的数据实现编辑窗口.在概念上与用于编辑Mail.app中的过滤规则的UI非常相似.
我有一个编辑窗口,我附加到我的主窗口:
[NSApp beginSheet: criteriaEditPanel
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(criteriaEditDidEnd:returnCode:contextInfo:)
contextInfo: (void *)[criteriaList objectAtIndex: index]];
Run Code Online (Sandbox Code Playgroud)
面板从主窗口的标题栏中正确显示.我可以使用鼠标操作面板上的弹出控件,但我无法编辑文本字段,我无法在字段之间切换.其他一切都很好.有任何想法吗?
乔
我的应用程序创建并打印一个 WebView。输出页面正在正确组装和打印,但我没有在打印面板中预览页面。
NSRect printViewFrame = {};
printViewFrame.size.width = paperSize.width - marginLR*2;
printViewFrame.size.height = paperSize.height - marginTB*2;
WebView *printView = [[WebView alloc] initWithFrame: printViewFrame frameName:@"printFrame" groupName:@"printGroup"];
[printView setShouldUpdateWhileOffscreen: YES];
// use the template engine to generate the document HTML
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *supportDir = [[paths objectAtIndex:0] stringByAppendingPathComponent: [[NSProcessInfo processInfo] processName]];
NSString *templatePath = [[supportDir stringByAppendingPathComponent: @"Templates"] stringByAppendingPathComponent: @"Default.mustache"];
GRMustacheTemplate *template = [GRMustacheTemplate templateFromContentsOfFile: templatePath error: NULL];
NSString *webviewHTMLString = [template renderObject: reportDict error:NULL];
// Print it
[[printView …Run Code Online (Sandbox Code Playgroud) 这是一个奇怪的.我的应用程序向控制硬件设备的对象发送关闭消息,并以完成块作为参数.关闭消息返回BOOL,具体取决于它是否能够立即完成关闭.所以YES表示它现在已经完成,NO表示它将在稍后完成时调用完成处理程序.
这是主控制器代码:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
BOOL shutdownNow = [theStoker shutdownWithCompletionHandler:^(void)
{
NSLog(@"applicationShouldTerminate: completionBlock");
[[NSRunningApplication currentApplication] terminate];
}];
if (!shutdownNow)
{
NSLog(@"applicationShouldTerminate: waiting for shutdown");
return NSTerminateCancel;
}
return NSTerminateNow;
}
Run Code Online (Sandbox Code Playgroud)
这是设备控制器代码:
- (BOOL)shutdownWithCompletionHandler:(void (^)(void))handler
{
if (busy)
{
self.completionBlock = handler;
[self stopDevice];
NSLog(@"shutdownWithCompletionHandler: Wait for reset");
return NO;
}
NSLog(@"Stoker: shutdownWithCompletionHandler: shutdown now");
return YES;
}
Run Code Online (Sandbox Code Playgroud)
奇怪的部分是关闭消息要发送两次.这些是NSLog消息:
shutdownWithCompletionHandler: Wait for reset
applicationShouldTerminate: waiting for reset
applicationShouldTerminate: completionBlock
shutdownWithCompletionHandler: shutdown now
Run Code Online (Sandbox Code Playgroud)
所以在完成块运行之后,我最终回到了设备对象的shutdownWithCompletionHandler:方法中.为什么?
编辑:嗯.[[NSRunningApplication currentApplication] terminate];导致 …