2010-03-08 67 views
0

好的,下面是加载Schedule nib的AppDelegate中的代码。Tableview not down down

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 

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

#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 
+0

我曾经穿过这个 - 通常我的tableView.dataSource和tableView.delegates没有正确连线。 我注意到你的接口使用UIViewController而不是UITableViewController。试试吗? – iPhoneDollaraire 2010-03-08 17:00:55

+0

如果我这样做,我会得到错误消息:' - [UITableViewController loadView]加载了“Schedule”笔尖,但没有得到UITableView。 难道是我不使用相同的头文件来声明标签栏并将其用作根视图控制器? – JoshD 2010-03-08 18:38:32

+0

重新回复下面的答案 - 是的,你需要做的不仅仅是这些。只是说Schedule实现协议是不够的。当您创建Schedule并将其推送到导航堆栈时,您需要明确设置Table View的委托。请在创建日程的地方发布代码,以便我们可以看一看。 – bpapa 2010-03-08 20:53:13

回答

0

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

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

  • 日程安排的导航控制器是否已设定?也就是说,它被推到导航控制器堆栈上吗?

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

+0

1.我有一个NSLog语句告诉我该方法正在被调用。 2.在“日程安排”中,我在头文件中声明它为。我需要在我的rootViewController中加载我的选项卡吗? 3.笔尖确实存在。 – JoshD 2010-03-08 19:37:45