簡體   English   中英

從Storyboard的UITableview中未調用initWithStyle

[英]initWithStyle not being called in UITableview from storyboard

我正在一個項目中嘗試使用此框架VPPDropdown,但我希望它與storyboard 提要一起使用。

那我該怎么辦? 我在屏幕上拖動了一個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;
}

經過一些研究,我發現當您在storyboard使用UITableViewController 上面的方法沒有被調用。 並且您應該將該代碼放入其中:

-(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''

有人可以幫我解決這個問題嗎?

使用Interface Builder時,應在此方法中放入初始化代碼:

- (void)awakFromNib
{

}

注意:盡管沒有[super awakFromNib]可以調用,也不要調用[super initWithStyle]。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM