50572

Sub-classed UITableView with background not displaying static cells

Question:

I am trying to make a view controller which deals with the user login. Since I needed the view controller to be scrollable, contain a separate view (for the login), and contain a background, I decided to go with the route of making a tableviewcontroller, subclassing it, and than adding in the necessary views. I subclassed UITableViewController and added this code into the viewdidload()

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewControllerBlurred.png"]]; [tempImageView setFrame:self.tableView.frame]; self.tableView.backgroundView = tempImageView; [tempImageView release];

This successfully added my background image to the controller and at this point, the view controller looked like: <a href="http://imgur.com/ST4H8uf" rel="nofollow">http://imgur.com/ST4H8uf</a> as it was supposed to.

Moving on, I began working with static cells, dropped in a view into one of the cells and began to design the sign in screen. At this point, my storyboard looked like: <a href="http://imgur.com/n6GKeGq&ST4H8uf" rel="nofollow">http://imgur.com/n6GKeGq&ST4H8uf</a> but the problem comes about when I run the project.

When I run the project, I keep getting the same background screen as seen in the first image without any of the new static cells or views. All and any help is much appreciated as to what may be the cause of this problem. Thank you.

CellForRowAtIndexPath Code:

*/ (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; // Configure the cell... return cell; } */

Answer1:

If what you want is a UITableView with just static cells, then learn to use UIScrollView with a UIViewController.

@interface vc : UIViewController @property (nonatomic, strong) UIScrollView *scrollView; @end @implementation vc - (id)init // or whatever initializer you are using to make your view controller { self = [super init]; if (self) { _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,568)]; [_scrollView setContentSize:CGSizeMake(320,568)]; // equals one screen [_scrollView setContentSize:CGSizeMake(320,568*2)]; // equals two screens, etc // contentSize property determines how much you can scroll inside the UIScrollView view if that makes any sense to you. [self.view addSubview:_scrollView] // one way of adding a background UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName"]]; [self.view addSubview:backgroundImageView]; [_scrollView addSubview:[self newStaticCellAtPosition:CGRectMake(0,0,320,45)]]; [_scrollView addSubview:[self newStaticCellAtPosition:CGRectMake(0,45,320,45)]]; // add subviews, you can even use UITableViewCell if you want. // I'd use simple UIView's and draw separators and whatnot myself if I were you. } return self; } - (UIView *)newStaticCellAtPosition:(CGRect)position { UIView *staticCell = [[UIView alloc] initWithFrame:position]; [staticCell setBackgroundColor:[UIColor redColor]]; return staticCell; } @end

For other properties you should check out UIScrollView documentation. Remember UITableView inherits from UIScrollView so if it's easy to pick and choose what you want.

Answer2:

first check datasource and delegate of tableview has to be set. You might be geeting a problem beacuse of that.

Answer3:

Never use a UITableViewController! In almost every case I have come across it is much much easier to use a UIViewController and add a table view. You simply cannot get at the backgroundView of a UITableViewController and have it scroll properly. I realize that you can only make a "static" table view with a UITableViewController but its simple enough to mimic the exact same behaviour with a regular table view and you don't have to deal with the headache of not being able to add views behind the table (like a background image).

Recommend

  • starttls on node.js > 0.4.0
  • Debian Jessie - Apache2 / PHP 5.6, can't upload more than 128kb
  • How to silently drop a request in Tomcat?
  • CSS: How to fix overlapping divs
  • Aligning image on right side of title on UIButton with imageEdgeInsets and titleEdgeInsets
  • Receiver has no segue with identifier“***”
  • Unable to play media with vlc ocx
  • cell spacing in div table
  • Can I programmatically choose the Android layout folder?
  • Using a canvas object in a thread to do simple animations - Java
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • Ajax calls do not work in IE unless you fiddle with security settings
  • Excel's Macro-Recorder usage
  • Avoid links criss cross / overlap in d3.js using force layout
  • Why is an OPTIONS request sent to the server?
  • Pass value from viewmodel to script in zk
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Optimizing database types to compact database (SQLite)
  • How do I fake an specific browser client when using Java's Net library?
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Excel - Autoshape get it's name from cell (value)
  • Controls, properties, events and timers running in design time
  • sending/ receiving email in Java
  • vba code to select only visible cells in specific column except heading
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Do I've to free mysql result after storing it?
  • QuartzCore.framework for Mono Develop
  • Python - Map / Reduce - How do I read JSON specific field in using DISCO count words example
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • How to delete a row from a dynamic generate table using jquery?
  • Proper way to use connect-multiparty with express.js?
  • File not found error Google Drive API
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy
  • Checking variable from a different class in C#
  • Converting MP3 duration time
  • How to load view controller without button in storyboard?