Reputation: 385
hi i'm studying iOS programming.
i have a wondering using interface builder.
i make a tableViewController and also make .xib file
now i can see the UITableView in interface builder.
i have to add a view, called myView, that contains buttons, labels and so on.
i want to myView be set the top of tableView's area, like tableview's header.
so i make a myView, and add buttons, labels, etc.
and i drag that view into UITableView. ok here's fine.
i can see myView is set the top of UITableView in interface builder.
but i run the program, myView doesn't appear.
of course wire up using IBOutlet, and declare property and synthesize.
but i use NSLog like this
if(self.myView == nil)
NSLog(@"omg it's nil!!!");
i can't understand that NSLog is printed my prompt area.
because i make that view in interface builder!
i can see tableView, of course can see the cells.
why myView doesn't appear??
how can i fix it??
i want to know how can i fix it using interface builder.
please help me
Upvotes: 1
Views: 2308
Reputation: 2142
The only way I've been able to get this to work is as follows:
(apparently the code won't format correctly if it's directly after a numbered list.)
[[NSBundle mainBundle] loadNibNamed:@"statsFooterView" owner:self options:nil];
self.tableView.tableFooterView = myFooterView;
Upvotes: 0
Reputation: 639
My experience with XCode 4.3:
you have to first place UITableView and UIView on the same super UIView. Then, when dragging UIView to the top of UITableView you'll notice XCode highlighting the option of inserting your view as footer.
Once done, you can detach UITableView from superview and delete it.
Upvotes: 2
Reputation: 9149
Not sure if this is possible using interface builder, I usually create a view manually and add it to the tableview header in the viewWillAppear method like so:
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 60)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10,self.tableView.bounds.size.width, 50)];
label.text = [person getFullName];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:25];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0,1);
[headerView addSubview:label];
self.tableView.tableHeaderView = headerView;
A simpler method would be to create a view in a separate nib file and then load it into the table header when you load the tableview like this:
UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"MYXIBFILEHERE" bundle:nil];
self.tableView.tableHeaderView = aViewController.view;
Upvotes: 2