gpt4 book ai didi

iphone - 如何在 UITableView 中制作固定背景 View ?

转载 作者:行者123 更新时间:2023-12-03 19:44:24 26 4
gpt4 key购买 nike

我正在尝试在分组的 UITableView 后面添加一个 View 。不幸的是,每当我滚动时,背景 View 也会移动。即使我使用 [self.view insertSubview:backgroundView belowSubview:_tableView] 或 [_tableView setBackgroundView:backgroundView] 也会发生这种情况。为什么这个背景 View 会滚动?另外,为什么我的 tableView 会滚动,即使我已禁用滚动?这些有关系吗?

在应用程序中委托(delegate):

    History *historyController = [[History alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:historyController];

历史.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];
}

最佳答案

尝试

- (void)viewDidLoad {

CGRect frame = self.view.frame;
frame.origin.x = 0;
frame.origin.y = 0;

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;

_tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
[_tableView setScrollEnabled:NO];
[_tableView setBackgroundColor:[UIColor clearColor]];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

[bg addSubview:_tableView];
[_tableView release];
_tableView = nil;
[self.view addSubview:bg];
[bg release];
bg = nil;

[super viewDidLoad];
}

如果您的 Controller 是UITableViewController只需将其更改为 UIViewController<UITableViewDelegate, UITableViewDatasource>tableView属性(相同)

关于iphone - 如何在 UITableView 中制作固定背景 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8402284/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com