2013-07-18 72 views
2

我正在嘗試使用此框架的項目VPPDropdown 但我希望它能與storyboard一起使用。initWithStyle不會在故事板的UITableview中調用

那我做了什麼?我在屏幕上拖動了一個UITableviewController。然後在我的代碼中,我有這個。

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
     _dropDownSelection = [[VPPDropDown alloc] initSelectionWithTitle:@"Selection Combo" 
                   tableView:self.tableView 
                   indexPath:[NSIndexPath indexPathForRow:kRowDropDownSelection inSection:kSection1] 
                   delegate:self 
                  selectedIndex:1 
                  elementTitles:@"Option 1", @"Option 2", @"Option 3", nil]; 

     _dropDownDisclosure = [[VPPDropDown alloc] initDisclosureWithTitle:@"Disclosure Combo" 
                   tableView:self.tableView 
                   indexPath:[NSIndexPath indexPathForRow:kRowDropDownDisclosure inSection:kSection1] 
                    delegate:self 
                  elementTitles:@"Disclosure 1", @"Disclosure 2", @"Disclosure 3", @"Disclosure 4", @"Disclosure 5", nil]; 


     NSMutableArray *elts = [NSMutableArray array]; 
     for (int i = 1; i <= 4; i++) { 
      // just some mock elements 
      VPPDropDownElement *e = [[VPPDropDownElement alloc] initWithTitle:[NSString stringWithFormat:@"Element %d",i] andObject:[NSNumber numberWithInt:i]]; 
      [elts addObject:e]; 
     } 

     _dropDownCustom = [[VPPDropDown alloc] initWithTitle:@"Custom Combo" 
                 type:VPPDropDownTypeCustom 
                tableView:self.tableView 
                indexPath:[NSIndexPath indexPathForRow:kRowDropDownCustom inSection:kSection2] 
                elements:elts 
                delegate:self]; 
    } 
    return self; 
} 

經過一番研究,我發現,當你使用一個UITableViewController裏面storyboard。上面的方法沒有被調用。而且你應該把這些代碼裏面:

-(id)initWithCoder:(NSCoder *)aDecoder { 
    if (!(self = [super initWithCoder:aDecoder])) return nil; 

    // Your code goes here! 

    return self; 
} 

當我這樣做,我得到以下錯誤

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/stefgeelen/Library/Application Support/iPhone Simulator/6.1/Applications/6D0EF4BF-068C-493C-A1A5-CFAA2B935D56/claesdistribution.app> (loaded)' with name 'DR7-d0-mee-view-dDq-is-22f''

任何人可以幫助我解決這個問題?

+1

如果你沒有實現'initWithCoder',一切都有效。 – Wain

回答

0

當使用界面生成器,你應該把初始化代碼在此方法改爲:

- (void)awakFromNib 
{ 

} 

注:沒有[超級awakFromNib]雖則打電話,不打電話[超級initWithStyle]無論是。

還應該注意的是,控制器中的許多UI元素可能尚未在awakFromNib中初始化,因此應該在viewDidLoad中更好地訪問其中的一些元素。

相關問題