开发者

iPhone: Creating a hierarchy-based table navigation

I've tried to ask this before, but nothing got answered. Basically, I would like someone to explain to me how to create a table, which when a cell is tapped, pushes the user to the next view for that cell. I have this so far:

Click here to view what I have.

I would further like to, say when CSS is tapped, it goes to a new view which has another table in it. This table would then take the user to a detail view, which is scrollable and you can switch pages through it.

I would appreciate longer, more structured tutorials on how to do each and every bit to get it to work.

Here's my array in my implementation file:

- (void)viewDidLoad {
    arryClientSide = [[NSArray alloc] initWithObjects:@"CSS", @"HTML", @"JavaScript", @"XML", nil];
    arryServerSide = [[NSArray alloc] initWithObjects:@"Apache", @"PHP", @"SQL", nil];
    self.title = @"Select a Language";
    [super viewDidLoad];
}

and my .h:

@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    IBOutlet UITableView *tblSimpleTable;
    NSArray *arryClientSide;
    NSArray *arryServerSide;
}

My current code crashes the script, and this error is returned in the console:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "NextView" nib but didn't get a UITableView.'

If that error is the source of why it's not pushing, then an explanation of how to remedy that would also be appreciated

NextViewController implementation

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    arryBasicCSS = [[NSArray alloc] initWithObjects:@"Implement", @"Syntax", @"Classes and IDs", @"Fonts", @"Backgrounds", @"Lists", @"Links",   nil];
    arryIntermediateCSS = [[NSArray alloc] initWithObjects:@"Padding and Margin", @"Alignment and Floating", @"Pseudo-class and Element", @"Opacity and Display", nil];
    arryAdvancedCSS = [[NSArr开发者_StackOverflow社区ay alloc] initWithObjects:@"Sprites", @"Attribute Selectors", @"Animation", nil];
    self.title = @"CSS";
    [super viewDidLoad];
}

- (IBAction) changeItemTable:(NSString *)str{
    tblCSS = str;
}

NextViewController.h

@interface NextViewController : UITableViewController {
    IBOutlet UITableView *tblCSS;
    NSArray *arryBasicCSS;
    NSArray *arryIntermediateCSS;
    NSArray *arryAdvancedCSS;
}

Many thanks, Jack


First the "Terminating app due to uncaught exception" error. I noticed that your RootViewController contains:

    IBOutlet UITableView *tblSimpleTable;

Check to make sure that you have properly connected RootViewController's "view" property to your UITableView, and not just connected tblSimpleTable to your TableView. The view property in a UITableViewController needs to point to a UITableView.

Assuming that tblSimpleTable is the TableView that you want to control from this UIViewController, delete this outlet and just use the "view" or "tableView" property of the UITableViewController, they will both be valid.

For your original problem of hierarchical table views, have at look at this sample project:

TheElements


If the SDK's own documentation isn't providing the answers you need, try a Google search for UITableView Interface Builder tutorial. That should return a number of useful step-by-step tutorials.

The reason you're getting the exception is because you haven't connected your tblSimpleTable outlet to your table view object in Interface Builder.

iPhone: Creating a hierarchy-based table navigation

Open NextView.xib in Interface Builder. Select the File's Owner object. Open the Inspector pane, and you should see something similar to the image I've posted. Instead of "searchTable" yours should read "tblSimpleTable". To connect the outlet to the file's owner, click-and-hold on the circle to the right of "tblSimpleTable" and drag the line to your "tblSimpleTable" object.

iPhone: Creating a hierarchy-based table navigation

Save your changes, rebuild your project.


See this: http://adeem.me/blog/2009/05/19/iphone-sdk-tutorial-part-2-navigation-in-uitableview/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜