简体   繁体   English

ios) Objective-c 如何在分组表中添加背景图片

[英]ios) Objective-c How to add a background image in the grouped table

Hello I have a trouble customizing a background of the grouped table view.. Here's the code I used您好我在自定义分组表视图的背景时遇到了麻烦。这是我使用的代码

UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];
[window addSubview:backgroundView];
[backgroundView release];

yourTableViewController = [[ATableViewController alloc] initWithStyle:UITableViewStyleGrouped];
yourTableViewController.view.backgroundColor = [UIColor clearColor];
[window addSubview:yourTableViewController.view];

[window makeKeyAndVisible];

Thank you:)谢谢:)

+added) +添加)

I modified the codes but still not working.. These codes are in delegate.m, didFinishLaunchingWithOptions method我修改了代码但仍然无法正常工作。这些代码在delegate.m,didFinishLaunchingWithOptions方法中

tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];

UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];

tableViewController.tableView.backgroundView = backgroundView;
[window addSubview:backgroundView];
[backgroundView release];

tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
tableViewController.tableView.backgroundColor = [UIColor clearColor];
[window addSubview:tableViewController.tableView];

[window makeKeyAndVisible];

and in delegate.h tableviewcontroller is declared.. not sure about this part tho..并在delegate.h中声明了tableviewcontroller..不确定这部分......

@interface BetaVersionAppDelegate : NSObject <UIApplicationDelegate> {

UIWindow *window;
UINavigationController *navigationController;
UIViewController *viewController;
UITableViewController *tableViewController;

}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UITableViewController *tableViewController;

Thanx:)谢谢:)

You should set the backgroundView property of your table:您应该设置表的 backgroundView 属性:

yourTableViewController = [[ATableViewController alloc] initWithStyle:UITableViewStyleGrouped];

UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];


yourTableViewController.tableView.backgroundView = backgroundView;
[backgroundView release];
[window addSubview:yourTableViewController.view];

Try changing the UITableView property backgroundView instead of just view .尝试更改UITableView属性backgroundView而不仅仅是view

Try this尝试这个

put this code in - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView将此代码放入 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

delegate method委托方法

[tableView setBackgroundColor:[UIColor clearColor]];
[tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]];

Put this on -viewWillAppear method so you can extend your tableView.把它放在 -viewWillAppear 方法上,这样你就可以扩展你的 tableView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM