Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with navigation controller when set title
    text
    copied!<p>I want to make Navigation with 3 levels. I make the root controller and fill the table with data. But when I touch on some cell my application crash. This is part of my code:</p> <h1>NavAppDelegate.h</h1> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface NavAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @end </code></pre> <h1>NavAppDelegate.m</h1> <h1>import "NavAppDelegate.h"</h1> <pre><code>@implementation NavAppDelegate @synthesize window=_window; @synthesize navigationController=_navigationController; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the navigation controller's view to the window and display. self.window.rootViewController = self.navigationController; [self.window makeKeyAndVisible]; return YES; } - (void)dealloc { [_window release]; [_navigationController release]; [super dealloc]; } @end </code></pre> <h1>RootViewController.h</h1> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class SubCategory; @interface RootViewController : UITableViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; { SubCategory *subCategories; } @property (nonatomic, retain) SubCategory *subCategories; @end </code></pre> <h1>RootViewController.m</h1> <pre><code>#import "RootViewController.h" #import "SubCategory.h" #import "OffersViewController.h" @implementation RootViewController @synthesize subCategories; - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Sub Categories"; NSString *jsonArray = [NSString stringWithFormat:@"{ " @" \"sub-categories\": { " @" \"parent\": \"1\", " @" \"count\": \"2\", " @" \"sub-category\": [{ " @" \"id\": \"1\", " @" \"name\": \"Buy\" " @" }, " @" { " @" \"id\": \"2\", " @" \"name\": \"Sell\" " @" }] " @" } " @" }"]; SubCategory* categories = [[SubCategory alloc] init]; [categories parseJSON:jsonArray]; subCategories = categories; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [subCategories.subCategoryName count]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewController * offers = [[OffersViewController alloc] initWithNibName:@"OffersView" bundle:nil]; //offers.title = [NSString stringWithFormat:@"%@", [subCategories.subCategoryName objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:offers animated:YES]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cachedCell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] init] autorelease]; } cell.textLabel.text = [subCategories.subCategoryName objectAtIndex:indexPath.row]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } @end </code></pre> <h1>OffersViewController.h</h1> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface OffersViewController : UITableViewController &lt;UITableViewDelegate, UITableViewDataSource&gt;{ } @end </code></pre> <h1>OffersViewController.m</h1> <pre><code>#import "OffersViewController.h" @implementation OffersViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 0; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cachedCell"]; if (cell == nil) { cell = [[[UITableViewCell alloc] init] autorelease]; } cell.textLabel.text = @"niki"; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } </code></pre> <p>The exception is:</p> <pre><code>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "OffersView" nib but the view outlet was not set.' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload