views:

50

answers:

1

Hi. i have a scrollview which contains a uitableview and few buttons. i have added the uitableview from IB. and the table cells are created dynamically. i am adding a lable and a textfield for each table cell(Something like an input form for the user.) I have written code to resize the scrollview when the keyboard appears. So when i click on a textfield the keyboard comes up and takes up half of the screen, and scrollview takes the other half. the problem is , as soon as this happens, the tableview is altered and shows only the first cell of the table.I think the tableview gets clipped. No matter what i do, the tableview does not show the entire table... so wat am i doing wrong.

Heres my code.

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView.contentSize=self.view.frame.size;
}

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell= [[tableView dequeueReusableCellWithIdentifier:CellIdentifier] autorelease];
    if (cell==nil) {

        CGFloat fontSize = [UIFont labelFontSize]-3 ;
        CGFloat topMargin = floor(0.5 * (tableView.rowHeight - fontSize)) -2;

        cell = [[[UITableViewCell alloc]
             initWithFrame:CGRectMake(0, 0, 320, tableView.rowHeight)
             reuseIdentifier:CellIdentifier]
            autorelease];


    UILabel *labelHeading = [[[UILabel alloc]initWithFrame:CGRectMake(10.0, topMargin, 100.0, fontSize + 4)] autorelease];
    labelHeading.text= [[self.menuItems objectAtIndex:indexPath.row] objectForKey:@"itemName"]; 
    [cell addSubview:labelHeading];
    txtValue = [[[UITextField alloc] initWithFrame:CGRectMake(120,topMargin,150 ,fontSize + 4)] autorelease];
    txtValue.text=[NSString stringWithFormat:@" %@",[dataItems objectForKey:@"name"]];  
    [cell addSubview:txtValue];
    [scrollView addSubview:cell];
    }
return cell;
}

So can somebody help me. nybody got ideas?

A: 

I'm not sure exactly what's going on with your solution, but try this: select your UITableView in IB and on the "Size" properties tab (ruler), make sure that you have set proper resizing options (i.e. distance to borders, height, width rules)

Nick
i have checked the size properties. everythings fine. the problem is when the keyboard appears on the view, the size of the table is reduced to the size of table cell. and only the first cell is displayed. i solved it by resizing the tableview frame in textFieldDidEndEditing: method of textfieldDelegate. I know this is a wrong approach, but i dont see any other way.
Jayshree