我想在我的分組UITableView後添加一個視圖。不幸的是,每當我滾動時,背景視圖也會移動。甚至當我使用[self.view insertSubview:backgroundView belowSubview:_tableView]或[_tableView setBackgroundView:backgroundView]時,會發生這種情況。爲什麼這個背景視圖滾動?此外,爲什麼我的tableView滾動,即使我禁用滾動?這些有關係嗎?如何在UITableView中製作靜態背景視圖?
在應用程序的委託:
History *historyController = [[History alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:historyController];
在History.m:
- (void)viewDidLoad {
CGRect frame = self.view.frame;
frame.origin.x = 0;
frame.origin.y = 0;
_tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
[_tableView setScrollEnabled:NO];
[_tableView setBackgroundColor:[UIColor clearColor]];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
UIView *bg = [[UIView alloc] initWithFrame:frame];
[bg setBackgroundColor:[UIColor scrollViewTexturedBackgroundColor]];
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CenterFade.png"]];
iv.alpha = .750;
[bg addSubview:iv];
[iv release]; iv = nil;
[self.view addSubview:bg];
[self.view addSubview:_tableView];
[bg release]; bg = nil;
[_tableView release];
[super viewDidLoad];
}
我最終從模擬器中刪除了應用程序,當我再次運行時,此問題消失了。看起來像是某種沒有更新的錯誤,儘管反覆清理和重建。 (我已經從UITableViewController更改爲UIViewController)。 – arsenius