Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I got the table view to populate by taking this code out of KFBAppDelegate and putting it into the code for the button in KFBViewController.
Code:
ListViewController *lvc = [[ListViewController alloc]initWithStyle:UITableViewStylePlain];
    WebViewController *wvc = [[WebViewController alloc]init];
    [lvc setWebViewController:wvc];

The problem now is that when I select a row in the table view it doesn't go to the web view. I'm going to look at it to see if I can figure it out but if anyone has any suggestions, I would appreciate it. You guys have been awesome so far!

I'll be back when I either figure it out or need more help.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I got the table view to populate by taking this code out of KFBAppDelegate and putting it into the code for the button in KFBViewController.
Code:
ListViewController *lvc = [[ListViewController alloc]initWithStyle:UITableViewStylePlain];
    WebViewController *wvc = [[WebViewController alloc]init];
    [lvc setWebViewController:wvc];
That's good to hear. What debugging led you to this solution?

The problem now is that when I select a row in the table view it doesn't go to the web view
What delegate method is called when you select a row in a table and what debugging have you done in relation to it?
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
Here is the code in ListViewController that uses the web view:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Push the web view controller onto the navigation stack - this implicitly creates the web view controller's view the first time through
    [[self navigationController]pushViewController:webViewController animated:YES];
    
    // Grab the selected item
    RSSItem *entry = [[channel items]objectAtIndex:[indexPath row]];
    
    // Construct a URL with the link string of the item
    NSURL *url = [NSURL URLWithString:[entry link]];
    
    // Construct a request object with that URL
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    
    // Load the request into the web view
    [[webViewController webView]loadRequest:req];
    
    // Set the title of the web view controller's navigation item
    [[webViewController navigationItem]setTitle:[entry title]];
}

I haven't done any debugging yet because I haven't had a chance to really look at it further since I got the other part working. I just wanted to give an update to everyone who has been helping.

As far as the debugging that led me to fix the table view, it was a combination of adding break points, adding the NSLog statement in order to see what the count was, and what chown33 mentioned about some things in the AppDelegate file.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
As far as the debugging that led me to fix the table view, it was a combination of adding break points, adding the NSLog statement in order to see what the count was, and what chown33 mentioned about some things in the AppDelegate file.

Don't forget to also fix your linked images bug I mentioned earlier.
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
Don't forget to also fix your linked images bug I mentioned earlier.
Thanks for reminding me! I meant to ask you about that. How do you add them to the project? I thought you just copied them into xcode but apprently I was wrong.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Thanks for reminding me! I meant to ask you about that. How do you add them to the project? I thought you just copied them into xcode but apprently I was wrong.

Make sure you have checked the following option when adding those files:

attachment.php


P.S. Any progress on your latest bug?
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I did put a break point here and the application stopped running when I selected a row in the table view.

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Push the web view controller onto the navigation stack - this implicitly creates the web view controller's view the first time through
    [[self navigationController]pushViewController:webViewController animated:YES];
    
    // Grab the selected item
    RSSItem *entry = [[channel items]objectAtIndex:[indexPath row]];
    
    // Construct a URL with the link string of the item
    NSURL *url = [NSURL URLWithString:[entry link]];
    
    // Construct a request object with that URL
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    
    // Load the request into the web view
    [[webViewController webView]loadRequest:req];
    
    // Set the title of the web view controller's navigation item
    [[webViewController navigationItem]setTitle:[entry title]];
}
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I did put a break point here and the application stopped running when I selected a row in the table view.
So, your delegate method is being called. Good. Now it's time to make some predictions and do some debugging (NSLogs, debug console commands, code step-through, etc.) to confirm or debunk those predictions. Try and figure out what might cause your WebViewController not to appear.

P.S. I would suggest waiting to push the new controller until you've done the setup. Just seems like a more logical progression of steps.
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I added some NSLog statements to that delegate method to verify that it is getting the URL when a row is selected. It is getting the URL. Here are the results:

2012-10-29 15:19:26.539 KFBNewsroom[3697:c07] Link: http://kyfbnewsroom.com/2012/10/22/..._medium=rss&utm_campaign=rural-votes-matter-2
2012-10-29 15:19:26.540 KFBNewsroom[3697:c07] URL: http://kyfbnewsroom.com/2012/10/22/..._medium=rss&utm_campaign=rural-votes-matter-2
2012-10-29 15:19:26.547 KFBNewsroom[3697:c07] Request: <NSURLRequest http://kyfbnewsroom.com/2012/10/22/rural-votes-matter-2/?utm_source=rss&utm_medium=rss&utm_campaign=rural-votes-matter-2>
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I added some NSLog statements to that delegate method to verify that it is getting the URL when a row is selected.

Good. Any other predictions you want to make and test?

I find it is always a good idea to check if variables are nil when they shouldn't be. That frequently causes the app not to do what you expect it to do, because you are calling methods on a nil object, which is simply ignored.
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
The only property in that line is webViewController. Other properties in that method are webView, title, items, title, and link.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
What do you mean?

What kind of element is navigationController?

Yes, in this case it's a method call to an accessor, but in the overall scheme of things what is navigationController in relation to your ListViewController, which is a subclass of UITableViewController, which itself is a subclass of UIViewController?

It's a property, as can be seen in the UIViewController Class Reference.

So, what is the value of navigationController when you try to push the web view controller onto the navigation stack?
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I replaced
Code:
[[self navigationController]pushViewController:webViewController animated:YES];
with
Code:
[self presentViewController:webViewController animated:YES completion:nil];
and it works now.

I still have some things to figure out but I think I can work through them.

Thanks guys!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Yeah, in order to ease navigation, you'll probably want to integrate a UINavigationController at some point. I'd suggest right from the beginning and then push new view controllers onto the stack as you drill down. You might have a look through the entire View Controller Programming Guide for iOS to understand what your options are.

P.S.

I replaced
Code:
[[self navigationController]pushViewController:webViewController animated:YES];
with
Code:
[self presentViewController:webViewController animated:YES completion:nil];

Care to tell us what made you come to that decision?
 
Last edited:

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I've added this code to KFBAppDelegate and now I'm not sure how to push the navigationcontroller to the other views.

Code:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil]];
    self.window.rootViewController = nav;

I would think something like this

Code:
[[self navigationController]pushViewController:webViewController animated:YES];

I'm wanting the navigation bar with a back button on all views (except the root view obviously)

Here is the current project without the navigation controller code put in the appdelegate file for reference.
https://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom 4.zip
 

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
307
15
I'm wanting to have a tab bar with a home item and a couple of items that go to other views but I also want a navigation bar with a back button.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
I'm wanting to have a tab bar with a home item and a couple of items that go to other views but I also want a navigation bar with a back button.

Alright. What do you know about combining a tab-bar-based app with a navigation-based one? If not much, how are you planning on learning about it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.