0

在某些情况下,我遇到了奇怪的无限循环,将 setBackgroundView 用于 UITableView 外观。这是外观初始化:

UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"bg"]];
[[UITableView appearance] setBackgroundView:iv];

我有一个控制器:

@interface MyController : UITableViewController

它只有带有简单日志记录的init方法和viewWill*/viewDid*委托。没有其他的。在这种情况下,我会收到关于布局子视图的无穷无尽的消息:

2013-06-05 21:23:45.054 MyApp[16700:c07] init
2013-06-05 21:23:45.056 MyApp[16700:c07] viewDidLoad
2013-06-05 21:23:45.057 MyApp[16700:c07] viewWillAppear
2013-06-05 21:23:46.059 MyApp[16700:c07] viewWillLayoutSubviews
2013-06-05 21:23:47.061 MyApp[16700:c07] viewDidLayoutSubviews
2013-06-05 21:23:48.064 MyApp[16700:c07] viewWillLayoutSubviews
2013-06-05 21:23:49.066 MyApp[16700:c07] viewDidLayoutSubviews
2013-06-05 21:23:50.067 MyApp[16700:c07] viewWillLayoutSubviews
2013-06-05 21:23:51.069 MyApp[16700:c07] viewDidLayoutSubviews
2013-06-05 21:23:52.070 MyApp[16700:c07] viewWillLayoutSubviews

如果我切换到:

@interface MyController : UIViewController

一切进行得都很顺利。

这是预期的行为(我没有清楚地理解 UIAppearance)还是功能损坏?

UPD:在 AppDelegate 中初始化的外观。

UPD2:无限循环仅发生在从另一个推送的表视图控制器上

4

2 回答 2

0

根据 Apple 文档,UITableView有一个背景属性。

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundImage.png"]];

将图像设置为 UITableView 的背景是可能的,尽管有点复杂。有四个步骤:

1)将tableView的backgroundColor属性设置为clearColor,这样背景图就可见了。

[myTableView setBackgroundColor:[UIColor clearColor]];

2) 创建一个 UIImageView 的实例,并将其 image 属性设置为您希望出现在表格后面的图像。

UIImageView *tableBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage"]];

3) 设置 UIImageView 的 frame 属性,使其与 tableView 的大小相同:

[tableBackgroundView setFrame: myTableView.frame];

4) 更新 tableView 的 backgroundImage 属性以指向您的新 UIImageView 对象:

[myTableView setBackgroundView:tableBackgroundView];
于 2013-06-05T21:14:18.800 回答
0

根据这个答案 UITableView,不支持使用setBackgroundView. 所以这不是一个错误 - 它只是不受支持。

于 2013-06-05T20:28:00.807 回答