1

I am creating an app in which i want to display a table view and each cell of table view will be displaying 5 different images.Let me say in detail.I have 10 images and i want to show them in a table view .say 4 images in first row of table view then next 4 in next row ,then the remaining two in next row.Being a newbie i am unable to get a startup.Please help.Any help will be appreciated.

Thanks, Christy

Vipin
  • 4,718
  • 12
  • 54
  • 81

2 Answers2

1

I think for startup you can go over here

How to display the UITableView programmatically?

Ok if you know how to load a uitableview than I think you can get started with complex part.

You need to add this line of code in your cellForRow method

You need to set the frame size and image name according to your requirement

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:cellIdentifier];
    }
    if(indexPath.row == 0)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image1.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image2.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image3.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image4.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];
    }
    else if(indexPath.row == 1)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image5.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image6.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image7.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image8.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];
    }
    else if(indexPath.row == 2)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image9.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(14, 14, 15, 15)];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image10.png", ]];
        [cell.contentView addSubview:imageView];
        [imageView release];        
    }
    else
    {
        // Do something here
    }
    return cell;
}

Edit:

@Christy you can have a button that can make a table view scroll. But iphone users are used to see the scroll bar on the right of the table to see if the table has any more data or not.

But if you want to have a Button that scrolls the table than here is the code

In your cellForRow method of tableView in this block else if(indexPath.row == 2){} add a UIButton with a down arrow like this

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(220.0f, 5.0f, 150.0f, 38.0f)];
[button setImage:[UIImage imageNamed:@"Arrow"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
[button release];

and in the selector method

- (void)doSomething
{
    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]
}
rene
  • 41,474
  • 78
  • 114
  • 152
Robin
  • 10,011
  • 5
  • 49
  • 75
  • @robin: i think in both the links there is no details about the adding images. – Aravindhan Jun 08 '11 at 12:47
  • Thats because that @Christina asked how to get started, and I think these are the things that are more important think than adding images in cell to get started – Robin Jun 08 '11 at 12:55
  • adding 5 images to a cell thats what i want ,please tell – Vipin Jun 08 '11 at 13:08
  • is there any way to add Scroll button like an arrow to show user that he can scroll down.I want that feature in the second row. – Vipin Jun 08 '11 at 14:19
  • say my table view is empty and i added an image to the first row then i simultanoesuly added images to corresponding rows.my table view is only capable of showing two rows ,so when images are entered in the third row then i want to have a scroll button adjacent to third row which shows the user that there is data beneath to be scrolled.Please give an idea. – Vipin Jun 08 '11 at 14:45
1
    IBOutlet UIImageView *image,*image12;

    In .m file
cellforrowAtIndexPath
{  
  UIImage *image1=[UIImage imageNamed:@"name.jpg"];
    image=[[UIImageview alloc]initWithImage:image1];
    image.frame=CGRectMake(0,0,50,50);

    [cell addSubview:image];

UIImage *image13=[UIImage imageNamed:@"name.jpg"];
    image12=[[UIImageview alloc]initWithImage:image13];
    image12.frame=CGRectMake(50,0,50,50);

    [cell addSubview:image12];

}

Aravindhan
  • 15,608
  • 10
  • 56
  • 71