それで、これが状況です。私は、メイン ビュー内に _contentView とそのビュー内に _tableView を持つ XIB ファイルを持つ基本クラス SSSAdEnabledTableViewController を持っています。基本クラスは、広告の表示/非表示に使用されています。
次に、その基本クラスから継承する多数のサブクラスがあります。非標準のテーブル セル (この場合は SSSDataEntryTableCell) を必要とするものを除いて、ほとんどはテーブル ビューに関しては問題なく動作します。
スーパーを呼び出した後、サブクラスの viewDidLoad でそのカスタム テーブル セルの nib を登録しようとすると、機能せず、テーブル ビュー データ ソースとデリゲートが nil セルを返します。ただし、super を呼び出す前に NIB を登録すると、問題なく動作するようです。
私が持っている質問は、これが悪い習慣であり、これを行う必要性を引き起こしている何か間違ったことをしていることを示しているかどうかです.
関連するコード スニペットは次のとおりです。
基本クラス -- SSSAdEnabledTableViewController
@interface SSSAdEnabledEditTableViewController : UIViewController <ADBannerViewDelegate, UITableViewDataSource, UITableViewDelegate>
{
// the data table
UITableView *_tableView;
// our inner view (to show/hide ads)
UIView *_contentView;
// our ad banner
ADBannerView *_bannerView ;
}
@property (retain, nonatomic) IBOutlet UIView *contentView;
@property (retain, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, retain) ADBannerView *bannerView ;
@end
そしてそれはviewDidLoadメソッドです:
- (void)viewDidLoad
{
[super viewDidLoad];
//
// set the appropriate background color
//
UIColor *clr = nil ;
if ( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad )
{
clr = kSSSDefaultBackgroundColor ;
}
else
{
clr = [UIColor groupTableViewBackgroundColor] ;
}
[[self view] setBackgroundColor:clr] ;
[_tableView setAutoresizesSubviews:YES] ;
}
サブクラスの viewDidLoad メソッドの 1 つを次に示します。
- (void)viewDidLoad
{
// Load the NIB file for our custom cell -- do this before [super viewDidLoad]!
UINib *nib = [UINib nibWithNibName:kSSSDataEntryTableCell bundle:nil] ;
// Register the NIB which contains the cell
[_tableView registerNib:nib forCellReuseIdentifier:kSSSDataEntryTableCell] ;
[super viewDidLoad];
// ... does some other stuff not relevant to the question at hand ...
}
そのため、最初に [super viewDidLoad] を呼び出すと、NIB が登録されて失敗する前に、コードが cellForRowAtIndexPath の UITableView メソッドを呼び出しているように見えます。通話前に使用すると、問題なく動作するように見えます。
これはこれを行う正しい方法ですか、それとも間違っていますか?
ありがとう!