【问题标题】:allignment of images in table view cell is not proper表格视图单元格中的图像对齐不正确
【发布时间】:2015-02-19 08:13:37
【问题描述】:

我已经创建了带有图像的表格视图,但图像不在正确的行中。我希望所有图像都在同一行 帮助我在模拟器中显示所有图像,因为我有超过 7 个案例处于切换状态。

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

【问题讨论】:

  • 请正确格式化您的问题(使用 control+K 修复缩进问题,目前这很难阅读)
  • 图片大小一样吗?没有透明框?
  • 我明白了..我有很多案例,但只有 5 个案例被拿走并显示在模拟器中..为什么会这样??
  • 请更好地解释您的需求,以便我可以帮助您
  • 能否添加输出图片以便我们理解?

标签: ios uitableview


【解决方案1】:

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

应该改为:

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];

我必须包括我在开关盒中使用过的所有项目.. 那是我犯的错误

【讨论】:

  • 它的数量是 6,你的案例是 12。修复你的数组
【解决方案2】:

你的 cell.imageView 是 UITableViewCell 的默认大小。我建议你去界面生成器并在 UITableViewCell 中拖动一个 UIImageView 并定义它的大小并将 UIImageView 标记值设置为 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;
}

【讨论】:

  • 我已返回待办事项计数
  • 确保 - (NSInteger)numberOfRowsInSection:(NSInteger)section{ return 12;} 它返回 12 行检查您在 NSLog 中打印的数组大小并检查其大小
猜你喜欢
  • 2013-05-23
  • 2014-05-15
  • 1970-01-01
  • 1970-01-01
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多