2012-02-07 70 views
0

我需要有2种行。一个有高度的44 PX和其他与90像素:IOS TableView行高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.section == 0) 
     return 90.0; 
    else 
     return 44.0; 
} 

问题是,当我叫 - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath因为我需要添加到90px的单元格,它有90px的高度,但它被添加在单元格的中间,而不是顶部。

if (indexPath.section == 0) { 
     cell = [tableView dequeueReusableCellWithIdentifier:ScrolledCellIdentifier]; 
     if (cell == nil) 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ScrolledCellIdentifier]; 
     //cell.textLabel.text = @"hi"; 

     [cell addSubview:self.scrollView]; 
    } 

尝试设置单元格的作品为textLabel,问题是增加了滚动。

如果我这一行添加到代码:

self.scrollView.frame = CGRectMake(0,-45, 320, 90); 

它完美,但它听起来有些怪异我。发生什么事?

+0

只是为了澄清 - 你为什么需要调整滚动视图的框架? – theTRON 2012-02-07 21:42:28

+0

,因为如果我不调整框架,它需要高度44像素谢谢! – xger86x 2012-02-08 02:48:03

回答

0

我使用此代码解决了我的问题:

cell = [tableView dequeueReusableCellWithIdentifier:ScrolledCellIdentifier]; 
if (cell == nil) 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ScrolledCellIdentifier]; 
cell.frame = CGRectMake(0, 0, 320, 90); 
self.scrollView.frame = CGRectMake(0,0, 320, 90); 
[cell addSubview:self.scrollView]; 

我不知道这是错的,但它的工作原理...

0

在添加之前,将scrollView的框架设置为单元格的边界。

所以

self.scrollView.frame = cell.bounds; 
[cell addSubview:self.scrollView]; 

调试...... NSLog的....输出,其中,而不是您想要的地方被定位之后就被定位在物联网框架,所以你可以看到。使用此输出帧坐标:

NSLog(@"Frame is: ", NSStringFromCGRect(self.scrollView.frame)); 

或定义了一个快捷方式,因为我用这一切的时候

#define LogCGRect(rect) NSLog(@"CGRect:%@", NSStringFromCGRect(rect)); 

那么你可以做

LogCGRect(self.scrollview.frame); 
0

它只是适合滚动查看到tableviewcell,不管它的高度是44还是90.