Permalink
Browse files

do not override loadView since subclasses might want to do so for app…

… level code.

Moved view hierarchy construction to new loadBaseView method, that subclass may (e.g. if they are not using nibs) or may not call (no need if they are using nibs)
Also see http://goto0.com/a/283
  • Loading branch information...
1 parent 49734de commit f142aafab5483ea0e51f8fd9119551acdc2a4694 @ettore committed Nov 1, 2012
Showing with 19 additions and 9 deletions.
  1. +10 −0 CLCGTVVC.h
  2. +9 −9 CLCGTVVC.m
View
@@ -61,6 +61,16 @@ enum CLCGLoadingState {
// use this if you don't use a nib
-(id)initWithStyle:(UITableViewStyle)style;
+// if a subclass does not use a nib file, you should call this method in your
+// loadView implementation to create the base view structure (this includes
+// a background view and a TableView on top of that. The reason why this is
+// NOT done inside a local loadView implementation is because UIKit prohibits
+// to override loadView if the actual class uses a nib file: since this is a
+// base class and subclasses MIGHT use a nib file, we leave the task of actually
+// building the views hierarchy up to the user (either as a nib or by calling
+// loadBaseView inside the actual loadView implementation).
+-(void)loadBaseView;
+
// deselects all currently selected rows.
-(void)deselectAll:(BOOL)animated;
View
@@ -77,13 +77,8 @@ -(void)doInitCore
#pragma mark - View creation
--(void)loadView
+-(void)loadBaseView
{
- if ([self nibName]) {
- NSAssert(mTableView != nil, @"NIB file didn't set tableView.");
- return;
- }
-
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
UITableView *tv = [[UITableView alloc] initWithFrame:CGRectZero style:mStyle];
@@ -93,9 +88,6 @@ -(void)loadView
[v setAutoresizingMask:expandmask];
[tv setAutoresizingMask:expandmask];
- // necessary to avoid default striped background for grouped tableviews
- [tv setBackgroundView:nil];
-
// build view hierarchy
[self setView:v];
[self setTableView:tv];
@@ -107,6 +99,14 @@ -(void)loadView
}
+-(void)viewDidLoad
+{
+ [super viewDidLoad];
+
+ // necessary to avoid default striped background for grouped tableviews
+ [mTableView setBackgroundView:nil];
+}
+
//-----------------------------------------------------------------------------
#pragma mark - UITableView behavior

0 comments on commit f142aaf

Please sign in to comment.