Uitableview ios 5中tableView中的自定义单元格

Uitableview ios 5中tableView中的自定义单元格,uitableview,ios5,uilabel,Uitableview,Ios5,Uilabel,我试图在特定的indexath.row处减小单元格的一个标签的宽度,但它不起作用。。 下面我添加了代码,我使用的是iOS5情节提要。 有没有其他方法可以在运行时更改标签的大小 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCe

我试图在特定的indexath.row处减小单元格的一个标签的宽度,但它不起作用。。 下面我添加了代码,我使用的是iOS5情节提要。 有没有其他方法可以在运行时更改标签的大小

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"name&email"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


}
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
UILabel *detail = (UILabel *)[cell viewWithTag:101];
if(indexPath.row == 0){
    nameLabel.text = @"Name : ";
    detail.text = @"";
}else if(indexPath.row == 1){
    nameLabel.text = @"Email : ";
     detail.text = @"";
}else if(indexPath.row == 2){
    nameLabel.text = @"Location Alerts";
    detail.text = @"Notifies people when they are close to a saved spot";
// here i am changing the width of lable
    detail.frame = CGRectMake(0, 0, 100, 0);
}else if(indexPath.row == 3){
    nameLabel.text = @"Share This App :";
    detail.text = @"(post to facebook/twitter)";
}else if(indexPath.row == 4){
    nameLabel.text = @"Review This App :";
    detail.text = @"(on iTunes)";
}else if(indexPath.row == 5){
    nameLabel.text = @"Get Help :";
    detail.text = @"(send an email to me)";
}
// Configure the cell...

return cell;
}

我不是专家,但我看到你在使用两种不同的标识符

如果我是你,我会尝试:

static NSString *CellIdentifier = @"name&email";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"name&email"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


    }

好吗?告诉我它是否有效:)

如果您在故事板中创建了自定义单元格,请检查标识符是什么并使用它。标识符应位于属性检查器下。如果标识符单元格,那么您的代码应该是这样的以获取单元格

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
如果您有一个名为详细信息的UILabel要更改其宽度,则可以通过更改并重用以前的帧原点大小高度来更改大小

detail.frame = CGRectMake(detail.frame.origin.x, detail.frame.origin.y, newWidth,detail.frame.size.height);
确保传递
detail.size.height
作为高度,以保持高度不变(在您的示例中,我注意到高度为0,这不会使其可见)。希望有帮助