我在那裏當你在Category
挖掘,下面的代碼被執行UINavigationController不出現?
- (void)categoryTapped {
CategoryGroupViewController *categoryGroupViewController = [[CategoryGroupViewController alloc] initWithNibName:@"CategoryGroupViewController" bundle:nil];
[self presentViewController:categoryGroupViewController animated:YES completion:nil];
}
CategoryGroupViewController.h
看起來像
@interface CategoryGroupViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UINavigationController *navigationController;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end
CategoryGroupViewController.m
看起來像
#import "CategoryGroupViewController.h"
#import "Helper.h"
static NSString *CellIdentifier = @"Cell";
@interface CategoryGroupViewController()
@property(nonatomic, strong) NSArray *categories;
@end
@implementation CategoryGroupViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// (todo) should come from API
self.categories = @[@"Food & Drink", @"Utilities"];
}
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSLog(@"categoryGroup View loaded");
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self];
self.navigationController.title = @"Pick Category";
}
...
}
當我運行我的應用程序Add View
,我在日誌中看到以下內容
2014-11-20 21:29:53.589 myapp-ios[30332:70b] categoryGroup View loaded
但在模擬器,我看到
爲什麼我看不到NavigationController
?
你在使用故事板嗎?導航控制器可以從那裏完全'關閉'.. – 2014-11-21 05:42:54
我認爲你只呈現'CategoryGroupViewController'它不是一個導航控制器,所以你想呈現一個視圖控制器將其設置爲導航控制器的根視圖控制器 – 2014-11-21 06:38:53
檢查是否在故事板中有導航控制器。 – 2014-11-21 07:57:33