开发者

Data updating in a UITableView that's the rootview of a SplitViewController

开发者 https://www.devze.com 2023-01-09 05:23 出处:网络
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开发者_JAVA百科?Because I wanted

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开发者_JAVA百科? 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.


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. }

0

精彩评论

暂无评论...
验证码 换一张
取 消