2011-06-15 64 views
0

我創建一個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)代碼也是。 任何人都可以告訴我一個重新調整文本標籤大小的好方法。

+0

如果有任何答案有幫助,您應該接受它。如果您需要關於此問題的進一步幫助,請提及它。 – 2011-06-19 18:13:43

回答

1

除了改變文本標籤的大小,你也會得到你想要的功能需要返回tableView:heightForRowAtIndexPath:方法中的適當高度。否則,任何佈局更改都不會反映出來。

0

從我的理解你應該永遠不會修改cellFor cell中的單元格內容,但cellForRowAtIndexPath。退房時看看我的questions之一。摘要:

所以黃金法則是:永遠不會改變 細胞結構你dequed 之後。如果您需要更改 結構,請使用不同的單元ID。 當然更可定製的是 單元格更容易被 重用它們的可能性。

0

我相信UITableView在爲cellForRowAtIndexPath請求之後實際展開了單元格。雖然我在,你應該使用一個可定製的電池道納本的答案達成一致,我相信你可以通過改變框架此委託方法中

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath