| User | Post | 
                
                  | 
                      
                        | 6:40 pmOctober 9, 2008
 |  
                        | colinhumber
 Noob |  
                        |  |  
                        | colinhumber |  
                        |  |  
                        |  |  
                        | posts 5 |  | 
                      
                        |  |  
                        | 
                            I have created a UIView to use as the tableHeaderView on a UITableView. The UIView was created as a simple view in interface builder that contains just a label. I can't figure out how to create the view from the nib file. I've tried the following lines and I keep getting errors: UIView *view  [[UIView alloc] initFromNibName:@”TestView” bundle:[NSBundle mainBundle]; and UIView *view = [[[NSBundle mainBundle] loadNibNamed:@”TestView” owner:self options:nil] objectAtIndex:0]; Any thoughts? |  | 
                
                  | 
                      
                        | 11:33 amOctober 10, 2008
 |  
                        | VertigoSol
 Moderator |  
                        |  |  
                        |  |  
                        |  |  
                        |  |  
                        | posts 26 |  | 
                      
                        |  |  
                        | 
                            make sure that the view has a file owner (viewcontroller) when you load the nib |  | 
                
                  | 
                      
                        | 1:50 pmOctober 10, 2008
 |  
                        | colinhumber
 Noob |  
                        |  |  
                        | colinhumber |  
                        |  |  
                        |  |  
                        | posts 5 |  | 
                      
                        |  |  
                        | 
                            
                              
                              VertigoSol said: make sure that the view has a file owner (viewcontroller) when you load the nib 
 I set the file owner to the view controller (UITableViewController) that will contain the UITableView. That works fine, but when I try to assign the created view to the tableViewHeader using self.tableView.tableViewHeader I get an exception. I created a subclass of UIView that contains an IBOutlet for the label on the view and set the type of the view in IB to that class but it's bombs out. I'm starting to get a little lost… |  | 
                
                  | 
                      
                        | 3:24 pmOctober 10, 2008
 |  
                        | VertigoSol
 Moderator |  
                        |  |  
                        |  |  
                        |  |  
                        |  |  
                        | posts 26 |  | 
                      
                        |  |  
                        | 
                            I Think what you need to do is add a subview to the tableViewHeader instead of trying to resassign it 
                              UIView* myView = …load from nib or manually created[self.tableView.tableViewHeader addSubview:myView];
 //release if nessisary The base uiview header probably has to be there for the table to use it |  | 
                
                  | 
                      
                        | 5:26 pmOctober 10, 2008
 |  
                        | colinhumber
 Noob |  
                        |  |  
                        | colinhumber |  
                        |  |  
                        |  |  
                        | posts 5 |  | 
                      
                        |  |  
                        | 
                            The code runs through fine but nothing appears when the subview is added to the tableHeaderView. The awakeFromNib method is run on the UIView subclass when the view is created, so at least I know something is happening but I'm at a loss as to why nothing is appearing in the header. |  | 
                
                  | 
                      
                        | 12:42 amOctober 11, 2008
 |  
                        | VertigoSol
 Moderator |  
                        |  |  
                        |  |  
                        |  |  
                        |  |  
                        | posts 26 |  | 
                      
                        |  |  
                        | 
                            here I was messing around with this I got this to workexample with UILabel as the header view
 
                              UILabel* label = [[UILabel alloc] initWithFrame: 
                              CGRectMake(0.0, 0.0, 300.0, 20.0)];
                               label.backgroundColor = [UIColor clearColor];label.font = [UIFont systemFontOfSize:20];
 label.textColor = [UIColor blackColor];
 self.tableView.tableViewHeader = label;just set frame cords to location you want |  | 
                
                  | 
                      
                        | 9:15 amOctober 11, 2008
 |  
                        | colinhumber
 Noob |  
                        |  |  
                        | colinhumber |  
                        |  |  
                        |  |  
                        | posts 5 |  | 
                      
                        |  |  
                        | 
                            The UILabel as the view works fine by itself. Eventually what I would like is to have the view include a couple of labels and an image. To do that I would need a UIView object that contains those elements, correct? But the UIView doesn't seem to want to display in the header, only individual elements. I just tried creating the view manually and not from the xib file and all the subviews (labels) are displaying properly. It almost seems like there's a small setting missing from the xib created view to get it to display. 
                              - (id)initWithFrame:(CGRect)frame{
 if (self = [super initWithFrame:frame])
 {
 UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
 description.text = @”TEST”;
 description.backgroundColor = [UIColor clearColor];
 
 UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 100, 50)];
 label2.text = @”TEST 2″;
 label2.backgroundColor = [UIColor clearColor];
 
 self.backgroundColor = [UIColor greenColor];
 [self addSubview:description];
 [self addSubview:label];
 // Initialization code
 }
 return self;
 }
 |  |