- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    NSDictionary *temp = [self.placeArray objectAtIndex:[indexPath row]];
    cell.textLabel.text = [temp objectForKey:@"name"];
    cell.detailTextLabel.text = [[temp objectForKey:@"distance"] stringByAppendingString:@" km from Banglore"];
    cell.imageView.image =[UIImage imageNamed:[temp objectForKey:@"category"]];
    return cell;
}

最佳答案

将您的单元格样式更改为UITableViewCellStyleDefault

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

如果要在单元格中添加两个标签,则将其添加到单元格的contentView中。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }



       // Configure the cell...
        NSDictionary *temp = [self.placeArray objectAtIndex:[indexPath row]];
        cell.textLabel.text = [temp objectForKey:@"name"];
    UIlabel *detailLbl = [[UILabel alloc]initWithFrame:CGRectMake(60,10,200,50)];
    [detailLbl setText:[[temp objectForKey:@"distance"] stringByAppendingString:@" km from Banglore"];];
[cell.contentView addSubView:detailLbl];
        cell.imageView.image =[UIImage imageNamed:[temp objectForKey:@"category"]];
        return cell;
    }

关于ios - 无法在TableView中查看图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19771119/

10-13 04:29