我正在尝试将标签栏应用程序设置为我的根控制器,其中一个标签是导航设置。在我的导航视图的根视图控制器上,我有一个子级别,它是UIViewController的一个子类,名为IntervalViewController。
我在Root View Controller(IntervalSetupViewController.m)中有这个:
#import "IntervalSetupViewController.h"
#import "IntervalViewController.h"
@implementation IntervalSetupViewController
@synthesize controllers; // My Array for the Table View Cells
- (void)viewDidLoad {
self.title = @"Interval Setup";
NSMutableArray *array = [[NSMutableArray alloc] init];
// Interval List Setup
IntervalViewController *newInterval = [[IntervalViewController alloc]
initWithStyle:UITableViewStylePlain];
newInterval.title = @"Interval 1";
[array addObject:newInterval];
[newInterval release];
self.controllers = array;
[array release];
[super viewDidLoad];
}
- (void)viewDidUnload {
self.controllers = nil;
[super viewDidUnload];
}
- (void)dealloc {
[controllers release];
[super dealloc];
}
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
return [self.controllers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *IntervalCell = @"IntervalCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IntervalCell];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:IntervalCell] autorelease];
}
// Configure the cell
NSUInteger row = [indexPath row];
IntervalViewController *newController = [controllers objectAtIndex:row];
cell.textLabel.text = newController.title;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark Table View Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
IntervalViewController *nextController = [self.controllers objectAtIndex:row];
[self.navigationController pushViewController:nextController animated:YES];
}
@end
这是控制台的错误屏幕: * - [IntervalViewController initWithStyle:]:无法识别的选择器发送到实例0x3b33e60 * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'*** - [IntervalViewController initWithStyle:]:无法识别的选择器发送到实例0x3b33e60'
我假设我将无效参数传递给我的initWithStyle方法,但我认为UITableViewStylePlain是一个有效的参数。我这样做了吗?我正在按照APress Beginning iPhone Development 3中的示例进行操作,并尝试将其修改为我想做的一点,但我是编码的新手。谢谢!
答案 0 :(得分:1)
initWithStyle用于初始化UITableViewController而不是UIViewController