gpt4 book ai didi

iPhone UITableView PlainStyle 与自定义背景图像 - 在代码中完成 "entirely"

转载 作者:行者123 更新时间:2023-12-03 18:37:50 24 4
gpt4 key购买 nike

我到处都是,似乎具有静态背景问题的 UITableView 有详细记录,但没有人有直接的解决方案?我完全用代码构建我的 TableViews,如下所示:

    UIViewController *tableViewController = [[TableViewController alloc] init];
navigationController = [[UINavigationController alloc]
initWithRootViewController:tableViewController];
[tableViewController release];
[window addSubview:navigationController.view];

该窗口是我在应用程序委托(delegate)中为我构建的主要 UIWindow 。从这里开始,我需要构建一些不同的 TableViews (由 navigationController 控制),其中一些带有 fetchedResultsControllers、自定义单元格等。我更喜欢完全在代码中完成此操作,而不是使用 nib,因为这会导致在代码和 IB 之间进行自定义扩展,或者必须构建和维护 6 个以上不同的 Nib。

我根本找不到一个工作示例,其中 tableViewController 类设置它自己的背景图像。如果我在其中一个 TableViews 中执行此操作(扩展 UITableViewController):

self.tableView.backgroundColor = backgroundColor;

我当然获得了 tableView 的背景颜色(顺便也为单元格着色,认为单元格从 tableView 继承了它们的颜色?),但我希望有一个静态背景图像我的细胞在上面上下滑动。不是随着用户手势上下滑动的“背景图像”。正是 GroupedStyle tableView 提供的功能,但是在 PlainStyle tableView 中:) ..并且使用代码完成,而不是 IB。

我想我必须清除表格 View 的背景颜色,然后在配置它们时设置单元格颜色,这样它们就不会变成透明的。然后以某种方式从 tableView 实例内部“潜入”tableView View 下方的背景图像?

我将如何解决这个问题,最好的解决方案是能够在 viewDidLoad 或 TableViewController 内的任何其他函数中执行此操作,以将我的所有自定义保留在一个位置。

希望有人能帮助我,我都用“谷歌搜索”了:)谢谢!

最佳答案

您需要将 Controller 设置为 UIViewController,而不是 UITableViewController。然后以编程方式将 tableview 添加到背景 imageView 上方。

@interface SomeController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
...
UITableView *tableView;
...
}
@property (nonatomic, retain) UITableView *tableView;
@end



@implementation SomeController

@synthesize tableView;

...

- (void)loadView {
[super loadView];
UIImageView *v = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
[v setImage:[UIImage imageNamed:@"table_background.png"]];
[self.view addSubview:v];


self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:self.tableView];
}
...
@end

关于iPhone UITableView PlainStyle 与自定义背景图像 - 在代码中完成 "entirely",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637738/

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