views:

66

answers:

1

Hopefully I'll get some help here.

Basic setup is this: My application swaps out the current Main View of the Main Window each time I want to switch to a new view. Why? Because I wanted to use a SplitView further on in the program (what's displayed in the SplitView depends on what's been selected before it).

What happens is the application reads in information from a text file, and populates a UITableView (1) with that information. The user then selects a cell, and clicks "next". The main window then ditches the previous table view, and creates a SplitView, which has a UITableView (2) as its root view, and another UITableView (3) as its detail view.

So, I've gotten the reading-in-from-file part working, as well as updating the detail view (3) to show an initalized view based on what was chosen in the original UITableView (1). However, I can't get the root view (2) to properly display options chosen from the original view (1).

What I do is I have the Main Window pull out the string that contains a file-name base from the original view (1), and feed the line to the Root View(2) of the SplitView. This root view then reads in the data from file, parses it accordingly (All data structures are being intialized, and functioning properly, I've checked), and then sends the first item to the DetailView (3) to be displayed. However, the root view itself remains blank, even though I updated the NSMutableArray it uses as a data source appropriately, and then called [controller.tableView reloadData].

Everything is properly hooked up in the .xib file as well. Does anyone have some tips that I can get?

Sorry for the lack of code, but the code is on a secured computer, meaning no 'net access. I can describe any code you want if you ask.

+1  A: 

Usually, a blank table is cause by returning an incorrect value from: – numberOfSectionsInTableView: or – tableView:numberOfRowsInSection: .

The table thinks it has no rows so it never displays them.


Update:

After making the array retain itself, it started working, but only after I stopped using [array count] for the number of rows in section. I have no idea why [array count] would cause an error (An EXC_BAD_ACCESS error no less) when I has just outputted the contents of the array through NSLog just a second ago

When you have sections, you have a nested data structure. The top or outer structure defines the sections and each section's lower or inner structure defines the rows for that section. If you return the count of the outer structure for the inner or vice versa you will get a crash because the table has the wrong number of rows or sections.

Suppose you have an array called "departments" wherein each element is a dictionary that looks like:

Department{
    (key = value)
    name = "Engineering";
    employees = ["Steve","Bob","Ted"];
}

To display this as a table you would return:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [departments count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *tmpEmployees= [[departments objectAtIndex:section] valueForKey:@"employees"];
    return [tmpEmployees count];

The important thing is to return the proper count for the proper part of the data structure. }

TechZen
Well, that was a good place to start. I get that the data is null after setting the data (I have an NSLog telling me when the data is updated, and then later in number of rows telling me the count of the NSMArray). So, now the problem comes down to tracking why my NSMutableArray is getting set to null, because I'm fairly sure I don't release it at any point.
Althane
Just a note: After making the array retain itself, it started working, but only after I stopped using [array count] for the number of rows in section.I have no idea why [array count] would cause an error (An EXC_BAD_ACCESS error no less) when I has just outputted the contents of the array through NSLog just a second ago. WTF?
Althane
See my update for an explanation.
TechZen
Ah. Thanks a ton for that. It's working properly now.
Althane