Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
First, you need to learn how to do basic debugging.

None of your code has any NSLogs in any of the table-view delegate or data-source methods. Yet those are precisely the methods that must work in order to populate and show a UITableView. You may believe those methods are being called, but debugging means confirming your beliefs by collecting evidence.

What is the evidence that tableView:cellForRowAtIndexPath: is being called? What would constitute evidence? The second question can be easily answered: hitting a breakpoint set on that method, or NSLog output in the console log that uniquely shows the method is executing. You've provided neither. Until you have a means for collecting evidence, and then showing that evidence, you're not debugging, you're only hoping or guessing.

By contrast, you have plenty of evidence that the URL contents is being fetched, and is being parsed as XML. The evidence-collecting mechanism is the presence of NSLog statements in the code. The actual evidence is in the form of actual output in the log. You need to apply the same principle of basic debugging to the table-view problem.


Second, you have this code:
Code:
@class RSSChannel;
@class WebViewController;

@interface ListViewController : UITableViewController <NSXMLParserDelegate, UITableViewDelegate, UITableViewDataSource>
{
    NSURLConnection *connection;
    NSMutableData *xmlData;
    RSSChannel *channel;
}
[COLOR="red"]@property (nonatomic, retain) UITableView *tableView;[/COLOR]
@property (nonatomic, strong) WebViewController *webViewController;

- (void)fetchEntries;

@end

Code:
@implementation ListViewController
[COLOR="red"]@synthesize tableView;[/COLOR]
@synthesize webViewController;

- (void) viewDidLoad
{
    [super viewDidLoad];
    [[COLOR="Red"]tableView[/COLOR] setDelegate: self];
    [[COLOR="red"]tableView[/COLOR] setDataSource:self];
}
I've hilited what I suspect is problematic code in red.

The potential problem I see is you're:
A) Overriding the tableView property.
B) Using a synthesized tableView ivar instead of a property.

Since a UITableViewController already provides a read/write tableView property, what do you hope to accomplish by overriding it?

What may be happening is the UITableViewController is using the property (as it should), but because you've used your synthesized ivar, the end result is two distinct variables, one in the inherited property and the other in your ivar. It's hard to say without doing some actual debugging with the debugger, and seeing what's passed to the table view delegate and data-source methods. In short, can't tell much without collecting evidence.

Frankly, it looks like you just threw in a new tableView property with an @synthesize in order to fix your earlier error where a tableView symbol name wasn't being found. The more sensible thing to do would be to use the existing tableView property instead of adding one. Read the UITableView reference doc, carefully note what it says about the provided tableView property, and think it through logically.

The other sensible thing to do is apply the basic evidence-collection debugging principle to your existing table-view delegate and data-source methods. If the methods are being called, you have the tableView object in the tableView parameter to the method. You can then see if it's the same as what's in the tableView property. If the methods aren't being called at all, even with breakpoints and/or NSLogs, then the absence of evidence by itself tells you something useful. Right now, there's no evidence or even evidence-collection anywhere regarding the table view.
 
The code you highlighted in red is there because it was a suggestion I received. I tried it and it didn't work.
 
The code you highlighted in red is there because it was a suggestion I received. I tried it and it didn't work.

Then why is it still there? You still have the same basic problem: no evidence is collected for anything associated with the table view delegate or data source.

What's the simplest thing that doesn't work? Debug that. If you add something that doesn't solve the problem, leaving it in to confound further debugging is a step backwards (more complexity, introduced bugs), not a step forward.

Take out the stuff that didn't solve the problem, then apply basic debugging.
 
I placed a breakpoint at tableView:cellForRowAtIndexPath: and it did not stop the application so it isn't executing that bit of code.
 
My first inclination is that it has something to do with the views. When the table view is the first view loaded in the other project, everything works as expected but now that there is a different view with buttons that gets loaded first and the table view doesn't load until a button is pressed, I think that may be screwing it up.
 
Exactly what does tableView:cellForRowAtIndexPath: have to do with the views?

Which protocol is tableView:cellForRowAtIndexPath: a member of? If that method in that protocol isn't being called, what does it suggest is missing?

To me, it suggests that a table view doesn't have a data-source object, or the data-source it does have isn't where the breakpoint was set.

If a table view doesn't have a data-source, what would be necessary to give it one?


At a minimum, I suggest reading the "Creating and Configuring a Table View" section of Table View Programming Guide for iOS. Confirm that your code does everything it's supposed to, according to the description under the "Basics of Table View Creation" heading.

You would probably also benefit by studying (i.e. reading and testing) the sample code linked as RELATED SAMPLE CODE in the blue left-hand column of that programming guide.
 
Could the issue with
Code:
tableView:cellForRowAtIndexPath:

not loading have something to do with the button that goes to the table view? I added break points to other parts of ListViewController and the rest of it seems to be working. The code for the button is:
Code:
- (IBAction)gotoPublicAffairs
{
    ListViewController *publicAffairs = [[ListViewController alloc] initWithNibName:nil bundle:nil];
    publicAffairs.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    // [self presentModalViewController:publicAffairs animated:YES];
    [self presentViewController:publicAffairs animated:YES completion:nil];
}
 
If I change

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // return 1;
    
    return [[channel items]count];
}

to return 1; and comment out return [[channel items]count];, the code below that wasn't being called gets called but still with an empty table view.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // return nil;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
    }
    RSSItem *item = [[channel items]objectAtIndex:[indexPath row]];
    [[cell textLabel]setText:[item title]];
    
    return cell;
}
 
I've also added
Code:
NSLog(@"channel items %d", [[channel items]count];
and get this returned
2012-10-25 13:31:28.916 Newsroom[3457:c07] channel items 10
 
When I hit the button to go to the table view, the console updates and displays

2012-10-25 15:24:29.722 Newsroom[4590:c07] channel items 0
 
I've also added
Code:
NSLog(@"channel items %d", [[channel items]count];
and get this returned
2012-10-25 13:31:28.916 Newsroom[3457:c07] channel items 10

Maybe you should go over the BNR book some more that you took that code from?

I can tell you that I fixed part your problem with 1 line of code.

Here is my hint, when the view gets called when your public affairs button gets pushed what causes the xml feed to get downloaded into the view.

After that you are going to have to work on your WebViewController for the rest.
 
Are you implying that there is something wrong with me trying to build on code that is in a book I've been reading?

I just think you just miss some points or did not go through the later exercises in the later chapters that build upon this code. That might help you in your struggles. There is a reason why they preach developer documentation so much.

Here is what I see with your application.

You are pulling the data.

You are loading a tableview.

Your data is either doing one of two things. It is either not being loaded into the tableview or being overwritten with blank information.
 
When I hit the button to go to the table view, the console updates and displays

2012-10-25 15:24:29.722 Newsroom[4590:c07] channel items 0

Great! So now you've confirmed that the dataSource methods are being called. As part of your basic debugging, what do you think your next steps should be?
 
As part of your basic debugging, what do you think your next steps should be?

I'm not exactly sure. It seems that when the button is pressed, the data that is supposed to be in the table view is being overwritten as Kashsystems mentioned.
 
Don't guess. Confirm.

I feel like it has already been confirmed. The console displays

2012-10-25 13:31:28.916 Newsroom[3457:c07] channel items 10

before pressing the button and displays

2012-10-25 15:24:29.722 Newsroom[4590:c07] channel items 0

after pressing the button. That tells me that blank data is being put in after the button press.
 
I feel like it has already been confirmed. The console displays

2012-10-25 13:31:28.916 Newsroom[3457:c07] channel items 10

before pressing the button and displays

2012-10-25 15:24:29.722 Newsroom[4590:c07] channel items 0

after pressing the button. That tells me that blank data is being put in after the button press.

Those log messages don't occur in isolation. There are messages that come before each one, and messages that come after. Context is crucial.

Some of the log messages occur due to parsing of XML retrieved from a URL asynchronously. The URL isn't going to be retrieved, and the XML isn't going to be parsed, until some time after the URL connection begins loading data. That's what asynchronously means: not at the same time.

The loading of the URL is started by the initWithStyle: method of the ListViewController class. Until the XML has been received and parsed, the RSSChannel object which is the underlying source for the tableView, will either be nil or hold no data. This sould be evident by looking at the order of log messages. In short, by seeing the complete context.

If the "channel items 0" log messages comes before a series of log messages from the XML parsing, then it's evidence that the table is trying to load data when no data is available (nil RSSChannel). If the "channel items 0" message comes after the XML parsing messages, it's evidence of something else entirely. Without seeing all the evidence, in correct order, it's impossible to determine what's happening. The order of messages in the log is part of the evidence of what's happening; it shows you when something happens.


The "channel items 10" message is most likely due to this code, hilited in red:
Code:
@implementation KFBAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil];
[COLOR="Red"]    ListViewController *lvc = [[ListViewController alloc]initWithStyle:UITableViewStylePlain];
[/COLOR]    WebViewController *wvc = [[WebViewController alloc]init];
    [lvc setWebViewController:wvc];
    ActionAlertsViewController *avc = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
    [avc setWebViewController:wvc];
    MarketUpdatesViewController *mvc = [[MarketUpdatesViewController alloc]initWithStyle:UITableViewStylePlain];
    [mvc setWebViewController:wvc];
    self.window.rootViewController = self.viewController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
I have no idea what the intent or purpose of this code is.

What this does is make several different view controllers, assign them all the same WebViewController object, then do nothing else with them. The variabls lvc, wvc, avc, and mvc are local variables. The objects are not stored into ivars, nor are they given as parameters to any other object which might keep them around. They're just alloc'ed, init'ed, given a WebViewController, then promptly forgotten (released, under ARC; leaked, under manual retain/release).

One hypothesis is that you believe these objects are kept alive, and are used in the KFBViewController class. But that doesn't make sense, since that class has this:
Code:
- (IBAction)gotoPublicAffairs
{
[COLOR="red"]    ListViewController *publicAffairs = [[ListViewController alloc] initWithNibName:nil bundle:nil];
[/COLOR]    publicAffairs.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    // [self presentModalViewController:publicAffairs animated:YES];
    [self presentViewController:publicAffairs animated:YES completion:nil];
}
The red-hilited line clearly shows another ListViewController being made (this time without being given a WebViewController), and that ListViewController is then presented. This one is almost certainly the origin of the "channel items 0" log message, for the likely reason that the table view will be asked to draw itself almost immediately, but there is almost no chance that the URL with the XML data will be loaded by that time.

Another hypothesis is that you somehow think these two ListViewController objects have a shared RSSChannel, because they are instances of the same class. This is not true. Instance variables are unique to each instance of a class.

To summarize, I don't know what you're expecting the controller-creation code in didFinishLaunchingWithOptions: to do, nor why you think it needs to be there. From what I can tell, it serves no useful purpose, because the controllers that are created are abandoned when that method returns, without ever being presented. An async operation (like loading a URL) will continue until completion, but the loaded data has no effect on the rest of the program. The data is not shared or used elsewhere, because the object that holds the data has been abandoned and is not visible to any other part of the program.


Your first post said you have a working table view in a working app, but you haven't shown any code from that. Without seeing that code, and thus seeing how that one actually works, there's no way for anyone here to tell you what differs between the one that works and the one that doesn't. All anyone can do is point at problems in the posted code.

And since the last code that was posted definitely had errors, all we can do is guess about how you fixed the previous problems, and what the code you're currently running looks like.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.