Tableview没有向下钻取

时间:2010-03-08 16:47:08

标签: iphone uitabbarcontroller uitableview tabs

好的,这是我的AppDelegate中加载Schedule nib的代码。

Schedule *newestVideoController = [[Schedule alloc] initWithNibName:@"Schedule" bundle:nil];
    newestVideoController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Schedule" image:[UIImage imageNamed:@"app-icon_2_newest.png"] tag:2];
    NSArray *controllers = [NSArray arrayWithObjects:navController, newestVideoController, nil];
    mainController.viewControllers = controllers;

现在这是我的日程表头文件。

#import <UIKit/UIKit.h>
#import "AnotherViewController.h"


@interface Schedule : UITableViewController
<UITableViewDelegate, UITableViewDataSource>    {
    NSArray *mySchedule;

}

@property (nonatomic,retain) NSArray *mySchedule;

@end

最后,这里再次是我的“计划”的实施文件。

#import "Schedule.h"
#import "AnotherViewController.h"


@implementation Schedule

@synthesize mySchedule;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return mySchedule.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //create a cell
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                   reuseIdentifier:@"cell"];
    //fill it with contents
    cell.textLabel.text = [mySchedule objectAtIndex:indexPath.row];
    //return it
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController release];



}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    NSString *myFile = [[NSBundle mainBundle] pathForResource:@"exercise" ofType:@"plist"];
    mySchedule = [[NSArray alloc] initWithContentsOfFile:myFile];

    [super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

1 个答案:

答案 0 :(得分:0)

需要更多代码/信息。看起来你实现了tableView:didSelectRowAtIndexPath:并正确地将另一个View Controller推入堆栈,所以很难说。但这是一个热门列表:

  • 你确定tableView:didSelectRowAtIndexPath:被调用吗?你设置了一个断点吗?如果没有,您可能忘记以编程方式或在Interface Builder中将Schedule类设置为委托。

  • 计划的导航控制器肯定是设定的吗?也就是说,它是否被推送到导航控制器堆栈?

  • 您确定AnotherViewController的nib文件存在吗?