NavController and 5 views

Discussion in 'iOS Programming' started by mngoose, Sep 27, 2012.

  1. mngoose macrumors member

    Joined:
    May 26, 2012
    #1
    All,

    Semi-new to Iphone Programming this forum has been a great resource.

    I am working with NaVcontroller and 5 screens. Currently have two working at once and can't seem to get the others working.

    what I am attempting to accomplish is this:

    The user logs in to the webservice (MYSQL DB) on the phone and then it presents a table view of the information out of the JSON array that I have parsed into it. when the user clicks on the row for the detail view it will not push the detail to the screen.

    If I alter the navcontroller to only allow the table and the detail it works fine.

    we have been working on this for three weeks and can't seem to get it to push from screen 1 to 2 to 3 for some reason that we are lost in.

    here is the code appdelegate.m
    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
        
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
    
    viewcontroller.m (second screen)
    Code:
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        username = username.text;
        password = password.text;
        
        NSLog(@"username=%@", username);
        NSLog(@"Password=%@", password);
        self.title = @"list view";
        
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
        
        NSURL *url = [NSURL URLWithString:@"url removed for privacy"];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [[NSURLConnection alloc] initWithRequest:request delegate:self];
        
    	// Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        data = [[NSMutableData alloc] init];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
    {
        [data appendData:theData];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
       
        
        news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
        [mainTableView reloadData];
    }
    
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The download could not complete - please make sure you're connected to either 3G or Wi-Fi." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [errorView show];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    }
    
    - (int)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
    - (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [news count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
        
        
        if(cell == nil){
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];
        }
        
        cell.textLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"dname"];
        
        cell.detailTextLabel.text = [[news objectAtIndex:indexPath.row] objectForKey:@"dlloc"];
        
        NSLog(@"%@", cell);
        
        
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewContoller" bundle:nil];
        detailViewController.title = [[news objectAtIndex:indexPath.row] objectForKey:@"dname"];
        detailViewController.newsArticle = [news objectAtIndex:indexPath.row];
        
    }
    
    
    let me know if you need to see other code.... and I will post it

    thanks
    RON
     
  2. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #2
    Code:
     
        self.window.rootViewController = self.viewController;
    
    Should be

    Code:
        self.window.rootViewController = navController;
    
    And in didSelectRowAtIndexPath: you have to push your view controller to the navigation stack.

    Code:
        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewContoller" bundle:nil];
        detailViewController.title = [[news objectAtIndex:indexPath.row] objectForKey:@"dname"];
        detailViewController.newsArticle = [news objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:detailViewController animated:YES];
    
     
  3. mngoose thread starter macrumors member

    Joined:
    May 26, 2012
    #3
    Code Breaker,

    It still will not push the view of detail to the screen

    every click just goes no where ...

    I can go from 1 to 2 but not 2 to 3.

    I am sure that it is a forrest for the trees type of thing that I am missing :)

    let me know what other code you need to see to help me out

    banging head against wall is no fun :)

    RON
     
  4. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #4
    Post your updated didFinishLaunchingWithOptions and didSelectRowAtIndexPath methods. You need to make both the changes CodeBreaker mentioned or it won't work.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    What are 1, 2 and 3? Try to be as specific as possible when describing your problem. Otherwise, it just makes it harder for us to follow.
     
  6. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #6
    Does DetailViewController initialise correctly? Is it nil by chance?

    Also, as Duncan C said, I am really not getting what's 1, 2 and 3 :)
     
  7. mngoose thread starter macrumors member

    Joined:
    May 26, 2012
    #7
    All,

    Here is the changes to the code that was requested


    didselectrow method in my viewcontroller that is in front of the detail view:

    Code:
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewContoller" bundle:nil];
        detailViewController.title = [[news objectAtIndex:indexPath.row] objectForKey:@"dname"];
        detailViewController.newsArticle = [news objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:detailViewController animated:YES];
        
        
    }
    
    appdelegate.m
    Code:
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.viewController = [[loginViewController alloc] initWithNibName:@"loginViewController" bundle:nil];
        
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
        self.window.rootViewController = navController;
        [self.window makeKeyAndVisible];
        
    
    screen 1 is my login in screen (loginviewcontoller.h /.m) that will allow users to auth to a json server on the back end where they will get the detail to go to screen 2 (which is ViewController.h /.m) then when they select a row it will go to screen 3 (DetailViewController.h .m) where they will potentially go to a fourth screen (just trying to get the three screens working right now) which will have a webview nd a back button (hopefully ) to het back to the detail view of that item that they selected on the screen 3 side.


    As I understand that its bad form to name files like ViewController this was a new project with the navController that me and my team had not done before so we left things blank and generic to make a proof of concept and once we had a working generated code we would sort everything out and label it appropriately when we went down to alpha and beta stage testing.

    Thanks for the assist guys
    RON
     
  8. mngoose, Sep 28, 2012
    Last edited: Sep 28, 2012

    mngoose thread starter macrumors member

    Joined:
    May 26, 2012
    #8
    more information....

    I placed a NSLog at the end of the ondidselect so that I can see what is in the detailViewcontroller and it just gives me blank lines in the output and wont go anywhere, so I am guessing that I have something jacked up either ion my connections or output stream to allow it to come forward on top of the uitableview in the ViewController file.


    UPDATE**

    ok i know that there is something in the detailViewController because I ran an nslog against both the title and the meat of what I am trying to present and it is all there just won't push the screen. I have tried self.navigationController and navController (as deemed as the navigation controller in appdelegat) and push, modal and custom views for the screen and it just won't move.


    any thoughts of where I might not be connected?

    RON
     
  9. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #9
    I suspect your table view controller does not have a navigation controller.
    After successful login, do you push the view controller that contains the table into the navigation stack?

    It should look something like this (in LoginViewController):
    Code:
    - (void)userDidLogin {
        ViewController *myTableViewController = [[ViewController alloc] init];
        [self.navigationController pushViewController:myTableViewController animated:YES];
    }
    
     
  10. mngoose thread starter macrumors member

    Joined:
    May 26, 2012
    #10
    Codebreaker,

    Thanks for all your help. This is the reason that I come to this forum. With a push in the right direction... I finally got it working the way tha I need to and it helped me solve another problem.

    Thanks again

    RON
     
  11. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #11
    Glad it worked. :)
     

Share This Page