Monday, September 23, 2013

UITableViewController Set Background Image

I have here a ItemViewController class (inherited from UITableViewController), did not use XIB files. Here I want to give UiTableView set a background,
 - (void) viewDidLoad 
{

CGRect rect = [[self view] bounds];
UIImageView * imageView = [[UIImageView alloc] initWithFrame: rect];
[ImageView setImage: [UIImage imageNamed: @ "girl.png"]];

[Self.view setBackgroundColor: [UIColor clearColor]]; / / (1)
self.tableView.opaque = NO; / / (2) (1,2) two lines can do without, background images can also be displayed
self.tableView.backgroundView = imageView;
}


The result is a background image can be displayed properly. Code of (1) (2) can not write two lines display a background picture, my question is:
1 (a) (2) two lines of code is used to do? I was in line to see someone write so I do not know in what circumstances to use these two lines of code.

2 This view and tableView What is the relationship? This is the view tableView subviews do? ?


Inherited from
UItableViewController ---------------- >> UIViewController

| |
V V
tableView (attribute) <------- What is the relationship??? -------> view (attribute)
Reply:
[Self.view setBackgroundColor: [UIColor clearColor]]; / / (1)
self.tableView.opaque = NO; / / (2) (1,2) two lines can do without, background images can also be displayed
self.view View Manager can be said that the root view here because of your tableview blocking it, so he's become irrelevant background color, the general view, such as your property here tableview default is NO transparency should Therefore, these two lines have little effect.

You build a xib file you can see their hierarchical relationships, dragging a tableview up default view subviews.

No comments:

Post a Comment