重新大小
问题描述:
我创建一个UITableView和UITable视图为textLabel写了下面的代码cellForRowAtIndexPath
重新大小
static NSString *CellIdentifier = @"RootViewControllerCellIdentifier";
UITableViewCell *cell = [self.tableView queueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
// Set appropriate labels for the cells.
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"Static Scenes";
**[cell.textLabel setFrame:CGRectMake(200, 20, 500,600)];**
cell.imageView.image=[UIImage imageNamed:@"RunOptionsImage.png"];
cell.imageView.frame=CGRectMake(15, 20, 55, 65);
break;
,你可以从上面的代码明白,我有命名为静态场景一个的tableview细胞为textLabel 。
in this code [cell.textLabel setFrame:CGRectMake(200,20,500,600)];我打算设置textLabel框架,但它不根据我设置的框架来调整大小。我用这个cell.textLabel.frame = CGRectMake(200,20,500,600)代码也是。 任何人都可以告诉我一个重新调整文本标签大小的好方法。
答
除了改变文本标签的大小,你也会得到你想要的功能需要返回tableView:heightForRowAtIndexPath:
方法中的适当高度。否则,任何布局更改都不会反映出来。
答
从我的理解你应该永远不会修改cellFor cell中的单元格内容,但cellForRowAtIndexPath。退房时看看我的questions之一。摘要:
所以黄金法则是:永远不会改变 细胞结构你dequed 之后。如果您需要更改 结构,请使用不同的单元ID。 当然更可定制的是 单元格更容易被 重用它们的可能性。
答
我相信UITableView在为cellForRowAtIndexPath请求之后实际展开了单元格。虽然我在,你应该使用一个可定制的电池道纳本的答案达成一致,我相信你可以通过改变框架此委托方法中
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
如果有任何答案有帮助,您应该接受它。如果您需要关于此问题的进一步帮助,请提及它。 – 2011-06-19 18:13:43