views:

352

answers:

3

Hi,

I already created a UIViewController, where I display text, picture and other information. Now I wanna be able to put somes cells (so a tableView) under this View. What is the best way to do that?

Do I have to create a UITableView and create an header with my picture, text.. or other possibility

Best Regards,

A: 

This depends on what you want the UITableViewCells to look. If you just want one line of text there is no need to create a custom cell, but instead create one within the code.

-(UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath {

   UITableViewCell *cell = [[UITableViewCell alloc] dequeueReusableCellWithIdentifier:@"someId"];

   if (cell == nil) {
      cell = [[[UITableViewCell alloc] 
                 initWithFrame:CGRectZero 
                 reuseIdentifier:someIdentifier] autorelease];
     ...
   }

However, if you need a photo along with some text it will be easier to create a UITableViewCell.xib file, add the UILabel, UIImageViews etc, then when creating the cell within the method shown above replace the

cell = [[[UITableViewCell alloc] initWithFrame ...

with

NSArray *nib = [[NSBundle] mainBundle] loadNibNamed:@"YourNibCustomCellName" owner:self options:nil];
cell = [nib objectAtIndex:0];
chris
IN fact the UIView that I created is static, the cell under the view will be display from a query in my database is not a problem. But I wanna know how to implement the tableView just under my controllerView
ludo
A: 

Ok I find a solution.

I created a simple UITableView. Inside that tableView I created a function:


-(void)setHeaderView {

    self.myHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 300)];
    self.tableView.tableHeaderView = self.myHeaderView;

}

And in ViewWillAppear I just have to call this function. So when I run the application it will display the View and under the View my TableView. I didn't know that was easy like that.

Best Regards,

ludo
+1  A: 

In response to your post about the solution: Not sure, but shouldn't you release myHeaderView at the end of setHeaderView() ?

Mihir Mathuria
Yes I forget it. thanks~
ludo