UITableViewCell图像视图

时间:2016-04-14 08:37:33

标签: ios objective-c uitableview right-to-left

我已使用自定义UITableView创建了UITableViewCell,我有UITableViewCell的.xib文件,我的应用程序语言是从右到左我想要显示UIImageView在单元格的右侧,为此目的定制我的单元格。但是当在UITableView更改表格视图模式并选择单元格时,我的图像视图显示在单元格的左侧并更改此位置,问题出在哪里?

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  PersonnelCell *cell = (PersonnelCell *)[self.tableView dequeueReusableCellWithIdentifier:@"PersonnelCell"];
  NSMutableArray *cells = [[NSMutableArray alloc] init];

  if (cell == nil) {
    cell = [[PersonnelCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PersonnelCell"];
  }
  cell.cellImage.image = [UIImage imageNamed:@"logo.png"];

  NSArray *personnels = [[PersonelList sharedList] allPersonel];

  if (tableView == self.searchDisplayController.searchResultsTableView) {

    NSArray *a = [[NSArray alloc] init];
    a = [self.resultData firstObject];

    NSString *s = [[a objectAtIndex:0] stringByAppendingString:@" "];
    s = [s stringByAppendingString: [a objectAtIndex:1]];

    cell.nameLabel.text = s;
    if ([[a objectAtIndex:2] isKindOfClass:[UIImage class]]) {

        cell.cellImage.image=[a objectAtIndex:2];
    }
  return cell;
}

4 个答案:

答案 0 :(得分:0)

我只是不能发表评论,它要求我有50个以上的代表。无论如何,要解决您的问题,您必须在视图中使用约束。在Xib中应用约束比以编程方式更容易。

答案 1 :(得分:0)

每个单元格都有默认的图像视图,如cell.imageView

可能你正在将图像设置为单元格的默认图像视图,这就是为什么它在左边

尝试更改图片视图的IBOutlet

如果不起作用,请尝试设置约束

顶部,前导和固定宽度,高度

答案 2 :(得分:0)

示例代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FAQCellIdentifier];

        if (!cell) {
            UINib *nib = [UINib nibWithNibName:@"FAQTableViewCell" bundle:nil];
            [tableView registerNib:nib forCellReuseIdentifier:FAQCellIdentifier];
            cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:FAQCellIdentifier];
        }

        FAQ *oFAQ = [self.mainList objectAtIndex:indexPath.row];

        cell.lblTitle.text = oFAQ.question;
        cell.yourImgView.image = [UIImage imageNamed: oFAQ.imgName];
        return cell;
    }

另外请检查您将imageView的约束设置为顶部,尾部,固定:宽度,高度

答案 3 :(得分:0)

//Utils.java
 public static boolean hasKitKat()
    {
        return Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT;
    }

//Your Activity
      public void applyKitKatTranslucency(int color) {
            if (Utils.hasKitKat()) {
                if (mTintManager == null)
                    mTintManager = new SystemBarTintManager(this);
                mTintManager.setStatusBarTintEnabled(true);
                mTintManager.setStatusBarTintColor(color);

            }
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
        }

Download custom cell from

enter image description here