Loading

Thursday, October 16, 2014

Get Root ViewController of StoryBoard

   

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    
    UINavigationController *NavController = (UINavigationController*)[mainStoryboard instantiateViewControllerWithIdentifier:@"NavController"];

    UIViewController *TheViewController=[[NavController viewControllers] objectAtIndex:0];

You need to specify the controller identifier for your navigation controller in the attributes inspector of the navigation controller

Friday, September 26, 2014

Get primitive type from NSNumber

 const char* type = [theValue objCType];
if (strcmp (type, @encode (NSInteger)) == 0)
{
    //It is NSInteger
}
else if (strcmp (type, @encode (NSUInteger)) == 0)
{
    //It is NSInteger
}
else if (strcmp (type, @encode (int)) == 0)
{
    //It is NSUInteger
}
else if (strcmp (type, @encode (float)) == 0)
{
    //It is float
}
else if (strcmp (type, @encode (double)) == 0)
{
    //It is double
}
else if (strcmp (type, @encode (long)) == 0)
{
    //It is long
}
else if (strcmp (type, @encode (long long)) == 0)
{
    //It is long long
}

Tuesday, August 19, 2014

Singleton Viewcontroller Storyboard

static id s_singleton = nil;
+ (id) alloc {
    if(s_singleton != nil)
        return s_singleton;
    return [super alloc];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
    if(s_singleton != nil)
        return s_singleton;
    self = [super initWithCoder:aDecoder];
    if(self) {
        s_singleton = self;
    }
    return self;

}

Wednesday, July 10, 2013

Create Navigationcontroller in View based application

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.Nav=[[UINavigationController alloc] initWithRootViewController:self.viewController];
    
    [self.window setRootViewController:_Nav];
    
    [self.window makeKeyAndVisible];

    return YES;