开发者

uiscrollview and uitableview

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.

Here's my code:

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

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *ce开发者_如何学Goll= [[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;
}

What can I try to resolve this?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜