Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Adding images to a cell in table view
- - (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;
- }
- 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];
- - (void)doSomething
- {
- [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES]
- }
- 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];
Add Comment
Please, Sign In to add comment