开发者

re size the UITable view textlabel

I created a UITableView and wrote the following code in 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;

as you can understand from the above code, i have a tableview cell textLabel named as Static Scenes .

in this code [cell.textLabel setFrame:CGRectMake(200, 20, 500,600)]; i am planning to set the frame of textLabel.but it not resizing according to the frame i set. i used this cell.textLabel.frame = CGRectMake(200, 开发者_Python百科20, 500,600) code also. can any one tell me a good way to re size the text label.


In addition to altering the text label's size you will also need to return an appropriate height in the tableView:heightForRowAtIndexPath: method. Otherwise, any layout changes won't reflect.


From what I understand you should never modify anything but cell content within a cell in cellForRowAtIndexPath. Check out one of my questions from a while back. Summary:

So the golden rule is: NEVER change the cell structure after you've dequed it. If you need to change the structure then use DIFFERENT cell IDs. Of course the more customizable is the cell the easier is the possibility to reuse them.


I believe that UITableView actually lays out the cell after it asks for cellForRowAtIndexPath. While I agree with donalbain's answer in that you should use a customizable cell, I believe you can get the functionality you want by changing the frame inside this delegate method

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜