Ios UITableViewCell图像视图
我已经用自己的自定义Ios UITableViewCell图像视图,ios,objective-c,uitableview,right-to-left,Ios,Objective C,Uitableview,Right To Left,我已经用自己的自定义UITableViewCell创建了UITableView,我有一个.xib文件用于UITableViewCell,我的应用程序语言是从右到左的,我想在单元格的右侧显示UIImageView,并为此自定义我的单元格。但在UITableView更改表格视图模式并选择单元格时,我的图像视图显示在单元格的左侧并更改此位置,问题出在哪里 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndex
UITableViewCell
创建了UITableView
,我有一个.xib文件用于UITableViewCell
,我的应用程序语言是从右到左的,我想在单元格的右侧显示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;
}
我只是不能发表评论,它要求我有50次以上的重复。无论如何,要解决问题,必须在视图中使用约束。在Xibs中应用约束比通过编程实现要容易得多。每个单元格都有默认的图像视图,如
cell.imageView
可能您正在将图像设置为单元格的默认图像视图,这就是它位于左侧的原因
尝试更改图像视图的输出
如果不起作用,试着设置约束条件
顶部、前导和固定宽度、高度示例代码:
- (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的约束设置为顶部、尾部、固定:宽度、高度
#import "CustomCell.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ID_CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = (CustomCell *)[[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
显示您的代码和模拟器的快照。这可能是因为tableview重用单元格,所以当第二次分配单元格时,它使用的是默认单元格。我正在为我的单元格中的所有视图添加约束我正在尝试。删除.h文件中图像视图的IBOutlet,并用另一个名称为损坏视图创建新的outlet,我也有这个问题。我的图像视图高度和宽度等于30,当应用程序图像视图中的更改图像视图状态为40*40时,这意味着我的图像视图将替换为cell.imageview@Qazal你能展示一下你的代码和模拟器截图吗?我的声誉相当于4我不能添加图片。