如何通过导航栏在同一个项目中连接xib和storyboard?

时间:2014-03-06 05:32:22

标签: xcode storyboard xib

我有一个由storyboard创建的项目,在项目中连接和移动每个viewcontroller的方法是通过导航栏(后面的底部)。我想在我的项目中应用由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.将ARViewController设置为新的unviewcontroller

中的自定义类

但是,当我运行项目时,它仍然在xib文件中运行,而不是在storyboard中运行unviewcontroller。

我的问题是:

  1. 在此视图中拥有导航栏的最简单方法是什么?将xib转换为storyboard或将导航栏直接转换为xib?

  2. 如何将此xib转换为故事板,以便导航栏可以在此页面中使用?

  3. 如何将带有背底的导航栏放到xib上? (我正在使用Xcode 5)

1 个答案:

答案 0 :(得分:1)

你应该使用UINavigationController这是你所有问题的答案。