2010-03-08 123 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