如何在同一个项目中通过导航栏连接xib和storyboard?
Posted
技术标签:
【中文标题】如何在同一个项目中通过导航栏连接xib和storyboard?【英文标题】:How to connect xib and storyboard by navigation bar in the same project? 【发布时间】:2014-03-06 05:32:22 【问题描述】:我有一个由故事板创建的项目,连接和移动项目中每个视图控制器的方法是通过导航栏(后底部)。我想在我的项目中应用由 xib 编写的 metaio sdk。 sdk 完美运行,但问题是 xib 不包含导航栏。该应用程序无法返回上一页。我曾尝试将 xib 转换为情节提要,但没有成功。
我有 ARViewController.h/m/xib
#import <UIKit/UIKit.h>
#import <metaiosDK/MetaioCloudPlugin/MetaioCloudPluginViewController.h>
@interface ARViewController : MetaioCloudPluginViewController
bool m_useLocationAtStartup; //!< Flag to indicate if we should use the location at startup
- (IBAction)onBtnClosePushed:(id)sender;
@end
.m
#import "ARViewController.h"
#import "ASImageSharingViewController.h"
@implementation ARViewController
#pragma mark - View lifecycle
- (void) viewDidLoad
[super viewDidLoad];
// use this call to move the radar position
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[self setRadarOffset:CGPointMake(-16, -20) scale:0.825f anchor:ANCHOR_TR];
else
[self setRadarOffset:CGPointMake(-4.5, -20) scale:0.55f anchor:ANCHOR_TR];
// add the popup view to the view hierarchy if it is not present there already.
if( ![self.objectContextView superview] )
// we add it to the screen
[self.view addSubview:self.objectContextView];
[self.objectContextView setHidden:YES];
#pragma mark - react to UI events
// Close the UIViewcontroller on pushing the close button.
- (IBAction)onBtnClosePushed:(id)sender
[self dismissViewControllerAnimated:YES completion:Nil];
#pragma mark - @protocol MetaioCloudPluginDelegate
/**
* Provide the channel number that should be opened by the plugin
* In order to get your channel ID, please signup as a developer on http://www.junaio.com/developer
* and create your own channel.
*
* If you want to use a location based channel, be sure to return 'YES' for (BOOL) shouldUseLocation,
* otherwise 'NO'.
*/
- (NSInteger) getChannelID
// TODO: fill in your channel ID here.
bool loadLocationBasedChannel = false;
if( loadLocationBasedChannel )
// set locationAtStartup to YES, because we're loading a location based channel
// that needs the location at the first request
m_useLocationAtStartup = YES;
return 4796; // Wikipedia EN channel
else
// set locationAtStartup to NO, because we don't need a location for the first request
// This is the default for all AREL XML channels that don't provide location based content
m_useLocationAtStartup = NO;
//return 174470; // AREL instant tracker
return 214841;
/** Optional
*
* return YES if the application should support location
* If you return NO here, your application will never access the location sensors.
* Most scan channels don't need a location, so NO can be returned here.
*/
- (BOOL) shouldUseLocation
return YES;
/** Optional
*
* return YES if the application should activate location sensors at startup
* This will cause the application requesting permission at startup
* Return YES here if you are using a location based channel that needs location at startup
* Returning NO will cause the request to the server having no location
*/
- (BOOL) shouldUseLocationAtStartup
return [self shouldUseLocation] && m_useLocationAtStartup;
///** Optional
// *
// * return YES to cache downloaded files
// * During the development phase it makes sense to return NO here,
// * if the channel content changes a lot.
// */
//- (BOOL) shouldUseCache
//
// return YES;
//
#pragma mark - Extras
/** Default implementation for Sharing a screenshot
*
* Feel free to adjust the source of ASImageSharingViewController to adjust its behavior or integrate the Facebook SDK
*/
- (void) openSharingViewController: (UIImage*) imageToShare
ASImageSharingViewController* controller = [[ASImageSharingViewController alloc] initWithNibName:@"ASImageSharingViewController" bundle:nil];
controller.imageToPost = imageToShare;
[self presentViewController:controller animated:YES completion:Nil];
//[controller release];
@end
我为将 xib 转移到情节提要所做的工作是: 1.创建空的unviewcontroller并删除默认视图。 2. 将视图从 ARViewController.xib 复制到新的 unviewcontroller 3.在new unviewcontroller中设置ARViewController为自定义类
但是,当我运行项目时,它仍然在 xib 文件中运行,而不是故事板中的 unviewcontroller。
我的问题是:
在此视图中设置导航栏的最简单方法是什么?将xib转换为故事板或将导航栏直接放入xib?
如何将此 xib 转换为情节提要,以便导航栏可以在此页面中工作?
如何将带后底的导航栏放到 xib 中? (我使用的是 Xcode 5)
【问题讨论】:
显示你的appDelegate.m
。
我的问题与***.com/questions/19594827/…类似
所以比现在有什么问题,有解释如何使用它。
根据上述问题的最佳答案,我仍然不明白该怎么做。我应该在哪里创建带有 initWithNibName 的 xib viewController 的实例,然后我应该把代码放在哪里来将这个控制器实例推送到导航控制器上??
检查fantageek.com/481/…***.com/questions/20337425/…
【参考方案1】:
您应该使用UINavigationController
这是您所有问题的答案。
【讨论】:
以上是关于如何在同一个项目中通过导航栏连接xib和storyboard?的主要内容,如果未能解决你的问题,请参考以下文章
如何在xib中为不同的UIViewcontroller设置不同的导航栏颜色?
Android中通过ActionBar为标题栏添加搜索以及分享视窗