2010-08-04 37 views
0

因此,我們最近開始爲我們公司開發用於iPad的應用程序。不幸的是,我們這裏沒有人做過任何iPhone/iPad的開發,所以我們只是在進行一些學習,然後展翅高飛。基本上,我們的問題在我們嘗試在點擊表格行時將視圖推送到屏幕上時發生。我們都不知道爲什麼它沒有這樣做,因爲代碼看起來100%正確。這裏是什麼didRowSelectedAtIndex:方法是這樣的:iPad/iPhone TableVIew幫助推動新視圖

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Navigation logic -- create and push a new view controller 

if(pdvController == nil) 
    pdvController = [[PersonDetailViewController alloc] initWithNibName:@"PersonDetailView" bundle:[NSBundle mainBundle]]; 

Person *aPerson = [appDelegate.people objectAtIndex:indexPath.row]; 

pdvController.aPerson = aPerson; 

[self.appDelegate.navigationController pushViewController:pdvController animated:YES]; 
} 

,這裏是爲toolbarSearchViewController頭:

#import <UIKit/UIKit.h> 

    #import "RecentSearchesController.h" 
    #import "PersonDetailViewController.h" 

    @class ToolbarSearchAppDelegate, PersonDetailViewController; 

    @interface ToolbarSearchViewController : UIViewController <UISearchBarDelegate, UIPopoverControllerDelegate, RecentSearchesDelegate> { 

    ToolbarSearchAppDelegate *appDelegate; 

     UIToolbar *toolbar; 
     UISearchBar *searchBar; 
    UITableView *resultsTable; 

     PersonDetailViewController *pdvController; 
     RecentSearchesController *recentSearchesController; 

    UITableViewController *resultsTableController; 
     UIPopoverController *recentSearchesPopoverController; 

    } 


    @property (nonatomic, retain) IBOutlet UIToolbar *toolbar; 
    @property (nonatomic, retain) UISearchBar *searchBar; 
    @property (nonatomic, retain) IBOutlet UITableView *resultsTable; 

    @property (nonatomic, retain) ToolbarSearchAppDelegate *appDelegate; 
    @property (nonatomic, retain) PersonDetailViewController *pdvController; 
    @property (nonatomic, retain) UITableViewController *resultsTableController; 
    @property (nonatomic, retain) RecentSearchesController *recentSearchesController; 
    @property (nonatomic, retain) UIPopoverController *recentSearchesPopoverController; 



    @end 

和ToolbarSearchAppDelegate標題:

#import <UIKit/UIKit.h> 

@class ToolbarSearchViewController; 

@interface ToolbarSearchAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    ToolbarSearchViewController *viewController; 
UINavigationController *navigationController; 


NSMutableArray *people; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet ToolbarSearchViewController *viewController; 
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 

@property (nonatomic, retain) NSMutableArray *people; 

@end 

終於personDetailController。 h:

#import <UIKit/UIKit.h> 

@class Person; 

@interface PersonDetailViewController : UIViewController { 

IBOutlet UITableView *tableView; 

Person *aPerson; 
} 

@property (nonatomic, retain) Person *aPerson; 
@property (nonatomic, retain) UITableView *tableView; 

@end 

我們變得非常惱火,因爲我們都不知道爲什麼它沒有加載,任何幫助或洞察你們可以提供的將是驚人的。我不確定你需要看什麼,所以如果你需要更具體的東西,讓我知道,我會發布它。謝謝!

ps。我不確定代碼標籤是如何處理所有Obj-c的古怪語法的,所以如果你看到語法錯誤,就忽略它們。假設語法正確,並編譯和運行...

回答

1

這行看起來有點奇怪:

[self.appDelegate.navigationController pushViewController:pdvController animated:YES]; 

試圖使它

[self.navigationController pushViewController:pdvController animated:YES]; 

編輯相加運行時,問題是你沒有導航控制器,所以你不能像這樣推視圖控制器。你可以做的,是推視圖控制器模態,使用

[self presentModalViewController:pdvController animated:YES]; 
+0

呀,這條線就是我們最初有。我忘了我們把它改成了另一條線,試圖嘗試一些不同的東西。將它改回這條線沒有任何區別。我現在要嘗試將打印報表全部整理出來,看看我是否能夠弄清楚發生了什麼...... – gabaum10 2010-08-04 14:20:31

+0

在另一個說明中,我已經在調試器中經歷了一百萬遍,並且它實際上已經到達這些行並執行它們,它只是沒有做任何事情。這讓我覺得導航控制器沒有正確連接到正確的插座,但我不確定它應該在哪裏。 – gabaum10 2010-08-04 14:23:41

+0

如果您從未手動設置'self.appDelegate',則它將爲零,並且調試器將愉快地執行'[nil.navigationController ...]'這是一個NOOP。 'NSLog(@「navcnt:%x」,self.navigationController);'查看你發送消息的地方。 – mvds 2010-08-04 14:36:19