1
- (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;
}
4

2 回答 2

4

将单元格的样式更改为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;
    }
于 2013-11-04T15:35:20.470 回答
1

Try this code

- (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"];
                cell.detailTextLabel.text = [[temp objectForKey:@"distance"] stringByAppendingString:@" km from Banglore"];
                //cell.imageView.image =[UIImage imageNamed:[temp objectForKey:@"category"]];

        //write this code 

         // Load the image with an GCD block executed in another thread
            dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
            dispatch_async(downloadQueue, ^{

                UIImage * image = [UIImage imageNamed:[temp objectForKey:@"category"]];

                dispatch_async(dispatch_get_main_queue(), ^{

                     cell.imageView.image = image;
                     cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
                     [cell setNeedsLayout];
                });
            });
            dispatch_release(downloadQueue);

        return cell;

            }
于 2013-12-20T12:13:32.550 回答