【问题标题】:How To Change UITableView Cell Height Equally & Show detailedTextLabel?如何相同地更改 UITableView 单元格高度并显示详细的TextLabel?
【发布时间】:2012-06-13 11:15:12
【问题描述】:

您好,我这里有这段代码。

- (void)viewDidLoad
{
    [super viewDidLoad];

    jsonURL = [NSURL URLWithString:@"http://oo.mu/json2.php"];
    jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL usedEncoding:nil error:nil];
    self.jsonArray = [jsonData JSONValue];

    // Do any additional setup after loading the view, typically from a nib.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [jsonArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [indexPath row] * 20;
}

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

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Name"];

    return cell;
}

我想要的是:

  1. 更改UITableView 单元格的高度,以便我可以容纳更多 textLabel 下的东西。 (目前,当我使用以前的 增加UITableView单元格高度的代码,每个单元格 从大到小,大小不一)。

  2. textLabel.text下显示detailedTextLabel 在它下面还有别的东西。

我该怎么做?

我试过了:

cell.textLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Name"];
cell.detailTextLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"Street"];
cell.detailTextLabel.text = [[self.jsonArray objectAtIndex:indexPath.row] objectForKey:@"City"];

但它没有显示出来。

【问题讨论】:

    标签: uitableview height cell detailtextlabel


    【解决方案1】:

    您可以根据您的要求创建具有尺寸的新 UItableview 单元格。后来

    -(Uitableview) cellForIndexPath {
        //add the customized Uitableviewcell.
    }
    

    通过这种方式,您可以根据您的要求创建表格视图单元格。我希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 2012-07-22
      • 1970-01-01
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多