Ios setAccessoryType销毁TableViewCell

Ios setAccessoryType销毁TableViewCell,ios,cocoa-touch,uitableview,Ios,Cocoa Touch,Uitableview,我使用一个自定义的tablecell,标签和图像用标签连接 如果我加上 [单元格设置访问类型:UITableViewCellAccessoryDisclosureIndicator] 它破坏了我的桌面视图。图像会破坏背景色 区别如下: 有人知道问题出在哪里吗? 谢谢 编辑: -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { 静态NSString

我使用一个自定义的tablecell,标签和图像用标签连接

如果我加上

[单元格设置访问类型:UITableViewCellAccessoryDisclosureIndicator]

它破坏了我的桌面视图。图像会破坏背景色

区别如下:

有人知道问题出在哪里吗? 谢谢

编辑:

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“TableCell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
if([self-labelCellNib]){
[[self-labelCellNib]实例化所有者:self-options:nil];
}否则{
[[NSBundle mainBundle]loadNibNamed:@“LabelCell”所有者:自选项:nil];
}
cell=self.labelCell;
self.labelCell=nil;
}
静态NSDateFormatter*dateFormatter=nil;
如果(dateFormatter==nil)
dateFormatter=[[NSDateFormatter alloc]init];
静态NSCalendar*日历;
如果(日历==nil)
日历=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSString*timeStampString=[sqlTime objectAtIndex:indexath.row];
NSTimeInterval _interval=[timeStampString doubleValue];
NSDate*createdAt=[NSDate DATE WITH TIME INTERVALICENS1970:_interval];
[日期格式化程序setDateStyle:NSDateFormatterLongStyle];
//塔贝伦·泽勒·艾因弗根的数据
UILabel*label4=(UILabel*)[带标签的单元格视图:label4];
label4.text=[NSString stringWithFormat:@“%@,[dateFormatter stringFromDate:createdAt]];
//配置单元格。。。
UILabel*label1=(UILabel*)[带标签的单元格视图:label1];
label1.text=[NSString stringWithFormat:@“%@%@”,[sqlData objectAtIndex:indexPath.row],sonderzeichen];
UILabel*label2=(UILabel*)[带标签的单元格视图:label2];
label2.text=[NSString stringWithFormat:@“Preis pro%@:%@€”,sonderzeichen,[sqlPreis objectAtIndex:indexath.row]];
UILabel*label3=(UILabel*)[带标签的单元格视图:label3];
UIImageView*图像=(UIImageView*)[带标记的单元格视图:图像\标记];
if(indexath.row==[itemsArray计数]-1){
image.image=[UIImage ImageName:@“default.png”];
label3.text=@“-”;
}如果([itemsArray计数]>1),则为else{
int data_old=[[NSString stringWithFormat:@“%@,[sqlData objectAtIndex:indexath.row]]intValue];
int data_new=[[NSString stringWithFormat:@“%@,[sqlData objectAtIndex:indexath.row+1]]intValue];
label3.text=[NSString stringWithFormat:@“%i”,数据\u旧数据\u新数据];
NSLog(@“%d--%d”,数据旧,数据新);
如果(新数据>旧数据){
image.image=[UIImage ImageName:@“pfeil_runter.png”];

}否则,如果(data_new您需要设置单元格的背景色,而不是contentView,但这在CellForRowatineXpath中不起作用。它需要位于willDisplayCell:ForRowatineXpath:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = indexPath.row % 2? [UIColor colorWithRed:228.0/255.0 green:244.0/255.0 blue:199.0/255.0 alpha:1]:[UIColor whiteColor];
}

至于图像被挤压,这与子视图的大小及其约束有关。我认为可以通过为两个标签(一对在另一对上下)设置宽度约束来解决这些问题,但要优先考虑如何将标签和图像添加到单元格?请发布CellForRowatineXpath。我已编辑了我的帖子。您应该将所有动态内容从CellForRowatineXpath移动到willDisplayCell。确定此操作并运行图像!但背景色不适用于willDisplayCellCode@Loko,您已将其更改为cell.backgroundColor不是cell.contentView.backgroundColor?我已经测试过了,对我来说效果很好。
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = indexPath.row % 2? [UIColor colorWithRed:228.0/255.0 green:244.0/255.0 blue:199.0/255.0 alpha:1]:[UIColor whiteColor];
}