2012-06-13 35 views
1

沒有堅持我有2個問題,我的RootViewController的它的定義是這樣的:設備上神祕的tableView代碼

@interface RootViewController : UIViewController

注:我宣佈按照我的RootViewController.m從的UITableViewDelegate方法,但他們評論。首先它是UITableViewController,但後來我將其更改爲UIViewController。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 

我如何喚醒我的應用程序:注意的

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    RootViewController *rootVC = [[RootViewController alloc] init]; 
    navigationController = [[UINavigationController alloc] initWithRootViewController:rootVC]; 
    navigationController.navigationBarHidden = YES; 

    [rootVC release]; 

    [window addSubview:[navigationController view]]; 
    [window makeKeyAndVisible]; 
} 

END;

  • 當我嘗試建立他以下錯誤

    2012-06-13 10:34:23.595 Astrobox[540:707] -[RootViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x151820

    2012-06-13 10:34:23.609 Astrobox[540:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x151820'

  • 崩潰的應用程序。如果我取消從的UITableViewDelegate它運行在設備上的方法,的iOS 5.1.1 (92206),但我的RootViewController看起來像UITableViewController - 在屏幕上從上到下的分隔符,並因爲它自然tableView反彈啓用,我可以很容易地修復我的公關在這裏使用下面的代碼,但我不認爲這是優雅的解決方案。

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    self.tableView.bounces = NO; 
    
+0

清理項目...... –

+0

沒有被使用'[RootViewController的正常工作 – h4cky

+0

可以顯示''RootViewController的(圖)廈門國際銀行,爲什麼alloc] init]'use'initWithNibName' –

回答

0

不要改變的UITableViewController到UIViewController..and寫

RootViewController *rootVC = [[RootViewController alloc] initwithnibname:@"YourXib/Nib name"]; 

,而不是

RootViewController *rootVC = [[RootViewController alloc] init]; 

應該解決您的problem.Also檢查的委託和數據源的tableview。你RootViewController的的

0

檢查筆尖文件。它可能連接到tableview控制器。

+0

我沒有使用xib/nib來構建RootViewController – h4cky

0

首先請不要設置表視圖委託和數據源,並檢查你的觀點是正確加載與否。之後設置視圖下面的代碼做負載..

tableView.delegate = self; 
tableView.datasource = self; 
and implement the < UITableViewDelegate , UITableViewDataSource > in your .h file. 
and implement all the 4 methods what ever you have mentioned above and don't call it explicitly. 
these are the delegate method they will call itself.