Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:04:42+00:00 2026-06-06T18:04:42+00:00

I’m finding it difficult to get started in Objective-C. I’m executing the following code

  • 0

I’m finding it difficult to get started in Objective-C.

I’m executing the following code when a button is clicked:

NSLog(@"hi");
MainMenuDriver *mainMenuDriver= [[MainMenuDriver alloc] initWithNibName:nil bundle:nil];
[[self navigationController]pushViewController:mainMenuDriver animated:YES];

I can see “hi” in the console when I hit the button, it’s just that the view should change to MainMenuDriver. But nothing happens!

Please help!

As per request for more code:

MainMenuDriver.h:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface MainMenuDriver : UIViewController <UINavigationControllerDelegate,CLLocationManagerDelegate>{
    IBOutlet UIButton *photos;
    IBOutlet UIButton *profile;

    IBOutlet UISwitch *onOffline;

    IBOutlet UILabel *label1;

    NSTimer *uploadGPS_timer;

    CLLocationManager *lm;
    NSString *lat;
    NSString *lng;
}
@property(nonatomic,retain) UIButton *photos;
@property(nonatomic,retain) UIButton *profile;
@property(nonatomic,retain) UISwitch *onOffline;
@property(nonatomic,retain) UILabel *label1;
@property (nonatomic,retain) NSTimer *uploadGPS_timer;
@property(nonatomic,retain) NSString *lat,*lng;

-(IBAction)showMessages:(id)sender;
-(IBAction)showFriends:(id)sender;
-(IBAction)showPhotos:(id)sender;
-(IBAction)showProfile:(id)sender;

-(IBAction)switchSwitched:(id)sender;

-(void)uploadGPS_tick:(NSTimer*)timer;
@end

MainMenuDriver.m

#import "MainMenuDriver.h"
#import "ASIFormDataRequest.h"
#import "JoeMaxiViewController.h"
#import "Photos.h"
#import "Profile.h"

@implementation MainMenuDriver
@synthesize messages,profile,photos,friends,label1;
@synthesize onOffline;
@synthesize uploadGPS_timer;
@synthesize lat,lng;

-(IBAction)showPhotos:(id)sender{
    [self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]];
    Photos *x= [[Photos alloc] initWithNibName:nil bundle:nil];
    [[self navigationController]pushViewController:x animated:YES];
}
-(IBAction)showProfile:(id)sender{
    [self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]];
    Profile *x= [[Profile alloc] initWithNibName:nil bundle:nil];
    [[self navigationController]pushViewController:x animated:YES];
}
-(void)logout:(id)sender{
    if([uploadGPS_timer isValid]){
        [uploadGPS_timer invalidate];
    }
    [lm release];
    //[uploadGPS_timer release];

    [self.navigationController popViewControllerAnimated:NO];




    /*NSString *urlStr=[[NSString alloc] initWithFormat:@"http://www.prestocab.com/driver/ajax/logout.php"];
    NSURL *url=[NSURL URLWithString:urlStr];
    __block ASIFormDataRequest *request=[[ASIFormDataRequest alloc ]initWithURL:url];
    [request setDelegate:self];
    [request setCompletionBlock:^{
        NSString *response=[request responseString];
        NSLog(@"%@",response);


    }];
    [request setFailedBlock:^{

    }];
    [request startAsynchronous];*/

}
-(IBAction)switchSwitched:(id)sender{
    if(onOffline.on){
        [label1 setText:@"For Hire"];
        [label1 setTextColor:[UIColor colorWithRed:0.0 green:0.8 blue:0.0 alpha:1.0]];

        uploadGPS_timer=[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(uploadGPS_tick:) userInfo:nil repeats:YES];
        [self uploadGPS_tick:nil];
    }else{
        [label1 setText:@"Engaged"];
        [label1 setTextColor:[UIColor colorWithRed:0.8 green:0.0 blue:0.0 alpha:1.0]];

        if([uploadGPS_timer isValid]){
            [uploadGPS_timer invalidate];
        }
    }

}
-(void)uploadGPS_tick:(NSTimer*)timer{
    if(!lat || !lng){
        //do nothing
    }else{
        NSString *urlStr=[[NSString alloc] initWithFormat:@"http://www.prestocab.com/driver/ajax/updateCoords.php"];
        NSURL *url=[NSURL URLWithString:urlStr];

        __block ASIFormDataRequest *request=[[ASIFormDataRequest alloc ]initWithURL:url];
        [request setPostValue:lat forKey:@"lat"];
        [request setPostValue:lng forKey:@"lng"];
        NSLog(@"EOH: %@",lat);
        [request setDelegate:self];
        [request setCompletionBlock:^{
            NSString *response=[request responseString];
            NSLog(@"%@",response);
            //do nothing
        }];
        [request setFailedBlock:^{
            //NSError *error =[request error];
            //do nothing
        }];
        [request startAsynchronous];
    }
}

-(void)locationManager:(CLLocationManager*) manager didUpdateToLocation:(CLLocation *) newLocation fromLocation:(CLLocation*) oldLocation{
    lat=[[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.latitude];
    lng=[[NSString alloc]initWithFormat:@"%g",newLocation.coordinate.longitude];
    NSLog(@"%@,%@",lat,lng);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    self.navigationItem.title=@"PrestoCab";
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Logout" style:UIBarButtonItemStylePlain target:self action:@selector(logout:)];      
    self.navigationItem.rightBarButtonItem = anotherButton;
    [anotherButton release];


    //GPS
    lm=[[CLLocationManager alloc] init];
    if([CLLocationManager locationServicesEnabled]){
        lm.delegate=self;
        lm.desiredAccuracy=kCLLocationAccuracyBest;
        lm.distanceFilter=30.0f;
        [lm startUpdatingLocation];
    }
    //[self check4messages_tick:nil];   //want to start immediately, not in 10/40 seconds' time
    [self uploadGPS_tick:nil];
    //check4messages_timer=[NSTimer scheduledTimerWithTimeInterval:40.0 target:self selector:@selector(check4messages_tick:) userInfo:nil repeats:YES];
    uploadGPS_timer=[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(uploadGPS_tick:) userInfo:nil repeats:YES];



    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    if([uploadGPS_timer isValid]){
        [uploadGPS_timer invalidate];
    }
}
-(void)dealloc{
    [super dealloc];
    [uploadGPS_timer release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Also, here is

MyClassViewController.h:

#import <UIKit/UIKit.h>

@interface MyClassViewController : UINavigationController{
    IBOutlet UIButton *passenger;
    IBOutlet UIButton *driver;

}
@property (nonatomic,retain) UIButton *passenger;
@property (nonatomic,retain) UIButton *driver;

-(IBAction) passengerClicked:(id)sender;
-(IBAction) driverClicked:(id)sender;

@end

and MyClassViewController.m:

#import "MyClassViewController.h"
#import "MainMenuDriver.h"

@implementation MyClassViewController
@synthesize passenger;
@synthesize driver;

-(IBAction)passengerClicked:(id)sender{
    NSLog(@"passenger");
}
-(IBAction)driverClicked:(id)sender{
    NSLog(@"driver");
    MainMenuDriver *mainMenuDriver= [[MainMenuDriver alloc] initWithNibName:nil bundle:nil];
    [[self navigationController]pushViewController:mainMenuDriver animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:04:44+00:00Added an answer on June 6, 2026 at 6:04 pm

    I can see a couple of things:

    1. Your nib file’s name is different from the name of your class. If you put nil, the UIViewController will try to load a nib file with the UIViewController‘s name. Your UIViewController can be MainMenuDriver but your nib file name can be MainMenuDriverNibFileName.nib
    2. [self navigationController] is nil.

    For this, do the following:

        NSLog(@"hi");
        if([self navigationController]){
            MainMenuDriver *mainMenuDriver= [[MainMenuDriver alloc] initWithNibName:nil bundle:nil];
            [[self navigationController]pushViewController:mainMenuDriver animated:YES];
        }
        else{
            NSLog(@"Houston we have a problem");
        }
    

    Update 1:

    So, its nil, what you can do is the following:

    1. Quick and Dirty:

      [self presentViewController:mainMenuDriver animated:YES];

    2. Instead of UIViewController switch to a UINavigationController.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.