Iphone ios)Objective-c如何在分组表中添加背景图像
您好,自定义分组表视图的背景时遇到问题。。 这是我使用的代码Iphone ios)Objective-c如何在分组表中添加背景图像,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,您好,自定义分组表视图的背景时遇到问题。。 这是我使用的代码 UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame]; backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]]; [window addSubview:backgroundView]
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];
谢谢:)
+新增)
我修改了代码,但仍然不起作用。。
这些代码位于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];
并在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;
@接口BetaVersionAppDelegate:NSObject{
UIWindow*窗口;
UINavigationController*导航控制器;
UIViewController*viewController;
UITableViewController*tableViewController;
}
@属性(非原子,保留)IBUIWindow*window;
@属性(非原子,保留)IBuinavigationController*导航控制器;
@属性(非原子,保留)IBUITableViewController*tableViewController;
Thanx:)尝试更改
UITableView
属性backgroundView
而不仅仅是视图
尝试更改UITableView
属性backgroundView
而不仅仅是视图
您应该设置表的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];
您应该设置表的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];
试试这个
将此代码放入-(NSInteger)numberOfSectionsInTableView:(UITableView*)表格视图中
委托方法
[tableView setBackgroundColor:[UIColor clearColor]];
[tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]];
启用此选项-ViewWillDisplay方法,以便扩展tableView。尝试此选项
将此代码放入-(NSInteger)numberOfSectionsInTableView:(UITableView*)表格视图中
委托方法
[tableView setBackgroundColor:[UIColor clearColor]];
[tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground.png"]]];
启用-VIEWWILLEXPEND方法,以便扩展tableView。hmm仍然不起作用。。好的,我将用修改过的代码编辑这个问题,以确保我做的是Rythm,我仍然没有工作。。好的,我会用修改过的代码编辑这个问题,以确保我做得很好