开发者

Help with UITableView / Navigation Setup with UITabBar Interface

I'm trying to set up a Tab Bar Application as my root controller, and one of the tabs to be a Navigation setup. On my Root View Controller of the Navigation View, I have one child level that is a subclass of the UIViewController called IntervalViewController.

I have this in my 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
开发者_StackOverflow中文版

This is the error screen from the console: * -[IntervalViewController initWithStyle:]: unrecognized selector sent to instance 0x3b33e60 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[IntervalViewController initWithStyle:]: unrecognized selector sent to instance 0x3b33e60'

I assume that I am passing an invalid argument to my initWithStyle method, but I thought UITableViewStylePlain was a valid parameter. Am I setting this up right? I was following the example in APress Beginning iPhone Development 3 book and trying to modify it a little to what I wanted to do, but I'm new to coding. Thanks!


initWithStyle is used to initialize a UITableViewController not a UIViewController

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜