2012-05-02 30 views
0

我試圖使自定義視圖UITableView頭一個自定義視圖中查看插座沒有設置,但不幸的是,我得到一個異常:加載的筆尖,但同時賦予了UITableView中的頭球

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ImagesView" nib but the view outlet was not set.' 

第一,在HomeViewController中我創建了一個tableView,然後用xib文件創建了ImagesViewController,在那裏設計了我的自定義視圖。

而在最後,我嘗試分配ImagesView作爲我的tableView頭:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    ImagesViewController *imagesView = [[ImagesViewController alloc] init]; 
    tableView.tableHeaderView = imagesView.view; 

} 

我在做什麼錯?我是iOS開發的新手,並且自己弄明白。

感謝您的幫助!

+2

也調用的ViewController筆尖file.like此ImageViewcontroller *的ImageView = [[ImagesViewController的alloc] initwithnibname:@ 「ImageViewController」 束:無]; – vishiphone

+0

謝謝,你的建議有效! – Oleg

+0

Welcome.if評論對你有幫助,然後點擊我的評論中的箭頭標記。 – vishiphone

回答

3

使用這行代碼

{ 
ImageViewcontroller *imageView=[[ImagesViewController alloc]initwithnibname:@"ImageViewController" bundle:nil];  
} 
0

您可以創建自定義標題視圖使用這種方法

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 

這是UITableView Delegate Protocol一部分。

例如,我的應用程序一個使用此方法:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    UIView *customHeaderView = [[UIView alloc] init]; 
    customHeaderView.frame = CGRectMake(40.0, 20.0, 300.0, 45.0); 
    UILabel *headerText = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 300, 32)]; 
    headerText.textAlignment = UITextAlignmentCenter; 
    headerText.font = [UIFont systemFontOfSize:FONT_SIZE_FOOTER]; 
    headerText.numberOfLines = 0; 
    headerText.backgroundColor = [UIColor clearColor]; 
    if (section == 0) { 
     headerText.text = @""; 
    } 
    if (section == 1) { 
     headerText.text = SETTINGS_TEXT_PART0; 
    } 
    [customHeaderView addSubview:headerText]; 
    return customHeaderView; 
} 
0

嘗試這種方式,在tableviewcontroller本身的XIB文件,拖動一個UIView或ImageView的(這裏做頭設計)成在工作區中,但不進MAINVIEW或tableview中,然後使被稱爲報頭一個IBOutlet,那麼這IBOutlet中連接到視圖中,然後在tableviewcontrollers委託方法實現

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
return header; 
} 

添加此

0

在您的ImagesViewController中,您可能沒有將view插座與視圖相鏈接。您可以通過單擊文件所有者在界面生成器中執行此操作,並從實用程序單擊連接檢查器,您可以將view插座連接到您的UIView

相關問題