Проблема с навигационным контроллером при заданном заголовке - PullRequest
0 голосов
/ 31 мая 2011

Я хочу сделать Навигацию с 3 уровнями.Я делаю корневой контроллер и заполняю таблицу данными.Но когда я касаюсь какой-то ячейки, происходит сбой приложения.Это часть моего кода:

NavAppDelegate.h

#import <UIKit/UIKit.h>

@interface NavAppDelegate : NSObject <UIApplicationDelegate> {

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@end

NavAppDelegate.m

import "NavAppDelegate.h"

@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 

RootViewController.h

#import <UIKit/UIKit.h>
@class SubCategory;

@interface RootViewController : UITableViewController <UITableViewDelegate,          UITableViewDataSource> {
    SubCategory *subCategories;
}

@property (nonatomic, retain) SubCategory *subCategories;

@end

RootViewController.m

#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

OffersViewController.h

#import <UIKit/UIKit.h>

@interface OffersViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{

}

@end

OffersViewController.m

#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;
}

Исключение составляет:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "OffersView" nib but the view outlet was not set.'

1 Ответ

1 голос
/ 31 мая 2011

В владельце вашего файла xib вашего файла установите выходное представление для вида.

OffersViewController вид не установлен в вашем случае.

Поиск выхода представления в владельце файла OffersViewController и установка его в представление в Интерфейсном конструкторе, как показано.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...