分类的UITableView与背景不显示静态单元格

我试图做一个视图控制器,处理用户login。 由于我需要视图控制器是可滚动的,包含一个单独的视图(用于login),并包含一个背景,我决定去做一个tableviewcontroller的子类,并添加必要的视图。 我subclassed UITableViewController并将此代码添加到viewdidload()

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

这成功地将我的背景图像添加到控制器,在这一点上,视图控制器看起来像: http : //imgur.com/ST4H8uf,因为它应该。

接下来,我开始使用静态单元格,将视图放入其中一个单元格中,并开始devise屏幕上的login。 在这一点上,我的故事板看起来像: http : //imgur.com/n6GKeGq&ST4H8uf但是当我运行该项目时,问题出现了。

当我运行该项目时,我不断得到与第一个图像相同的背景屏幕,而没有任何新的静态单元格或视图。 所有和任何帮助,非常感谢什么可能是这个问题的原因。 谢谢。

CellForRowAtIndexPath代码:

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

如果你想要的只是静态单元格的UITableView,那么学习使用UIScrollView和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 

对于其他属性,您应该查看UIScrollView文档。 记住UITableView从UIScrollViewinheritance,所以如果很容易挑选你想要的。

首先检查数据源和tableview的委托必须设置。 你可能会因为这个问题而陷入困境。

永远不要使用UITableViewController! 在几乎所有我遇到过的情况下,使用UIViewController并添加一个表视图要容易得多。 你根本无法得到UITableViewController的backgroundView并让它正确滚动。 我意识到,你只能用UITableViewController创build一个“静态”表格视图,但是它的简单性足以模仿与普通表格视图完全相同的行为,并且不必处理令人头痛的不能添加视图表格(如背景图片)。