Mano Chitra R
Mano Chitra R

Reputation: 241

allignment of images in table view cell is not proper

i have created table view with images but that images are not in proper line .i want all images to be in a same line help me in this to display all images in simulator since i have more than 7 cases under switch.

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];



    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
    }
  UIImageView *imageView=[cell.contentView viewWithTag:1];
    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"wake up";
            cell.detailTextLabel.text = @"wake up at 6 am and get ready for office";
            cell.imageView.image=[UIImage imageNamed:@"wake-up-early-200.jpg"];
           break;
           case 1:
            cell.textLabel.text = @"remainders";
            cell.detailTextLabel.text = @"today is ajay's bday wish him ";
            cell.imageView.image=[UIImage imageNamed:@"remainders.jpg"];
            break;
        case 2:
            cell.textLabel.text = @"shopping";
            cell.detailTextLabel.text = @"buy vegetables,fruits,dresses";
            cell.imageView.image=[UIImage imageNamed:@"shopping.jpg"];
            break;
        case 3:
            cell.textLabel.text=@"meeting";
            cell.detailTextLabel.text=@"meeeting at lanuch pad by 4pm";
            cell.imageView.image=[UIImage imageNamed:@"meeting.jpg"];
            break;
          case 4:
            cell.textLabel.text=@"airport";
            cell.detailTextLabel.text=@"bala is coming receive him on time";
            cell.imageView.image=[UIImage imageNamed:@"airport.jpg"];
            break;
        case 5:
            cell.textLabel.text=@"games";
            cell.detailTextLabel.text=@"time for refresh";
            cell.imageView.image=[UIImage imageNamed:@"games.jpg"];
            break;
        case 6:
            cell.textLabel.text=@"lunch";
            cell.detailTextLabel.text=@"go to lunch by 1pm";
            cell.imageView.image=[UIImage imageNamed:@"lunch.jpg"];
            break;
        case 7:
            cell.textLabel.text=@"coffee";
            cell.detailTextLabel.text=@"go to ccd at 3pm";
            cell.imageView.image=[UIImage imageNamed:@"coffee.jpg"];
        case 8:
            cell.textLabel.text=@"super market";
            cell.detailTextLabel.text=@"buy household items";
            cell.imageView.image=[UIImage imageNamed:@"market.jpg"];
            break;
        case 12:
            cell.textLabel.text=@"iPhone app";
            cell.detailTextLabel.text=@"iPhone app development training";
            cell.imageView.image=[UIImage imageNamed:@"iphone.jpg"];
            break;
    case 11:
            cell.textLabel.text=@"home";
            cell.detailTextLabel.text=@"going to home by 11pm";
            cell.imageView.image=[UIImage imageNamed:@"home.jpg"];
            break;

        default:
            break;
    }




    //cell.textLabel.text = [todoitems objectAtIndex:indexPath.row];
    //cell.detailTextLabel.text = @"This Is A Very Very Long String";

        return cell;
}

Upvotes: 0

Views: 115

Answers (2)

Mano Chitra R
Mano Chitra R

Reputation: 241

todoitems=[NSMutableArray arrayWithObjects: @"1.wake up",@"2.remainders",@"3.shopping",@"4.meeting",@"5.airport",@"6.home",nil];

should change to:

todoitems=[NSMutableArray arrayWithObjects: @"1.wake up",@"2.remainders",@"3.shopping",@"4.meeting",@"5.airport",@"6.home",@"games",@"lunch",@"coffee",@"super market",@"iPhone app",@"home",nil];

I have to include all items which i have used in switch case.. that is the mistake i have done

Upvotes: 1

Shashi3456643
Shashi3456643

Reputation: 2041

Your cell.imageView is default size of UITableViewCell. I would recommend you go to interface builder and drag a UIImageView in UITableViewCell and define its size and give the UIImageView tag value equal to 1.

Here in cell for Index path delegate access UIImageView this way

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];


    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
    }
UIImageView *imageView=[cell.contentView viewWithTag:1];

    switch (indexPath.row) {
        case 0:
            cell.textLabel.text = @"wake up";
            cell.detailTextLabel.text = @"wake up at 6 am and get ready for office";

        imageView.image=[UIImage imageNamed:@"wake-up-early-200.jpg"];
           break;
           case 1:
            cell.textLabel.text = @"remainders";
            cell.detailTextLabel.text = @"today is ajay's bday wish him ";

        imageView.image=[UIImage imageNamed:@"remainder.jpg"];
            break;
    default:
        break;
}

Upvotes: 0

Related Questions