這是我每次滾動我的標籤時都會出現的代碼文本越來越重疊。文本重疊,我認爲這是因爲重複使用細胞。 我正在使用故事板,這不是一個自定義單元格。 需要一些幫助,每一個幫助將不勝感激。我有原型表格視圖單元格的問題,我的單元格文本每次重疊時都會重疊
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableViewCEll [email protected]"TableViewCell";
UITableViewCell *Cell = [tableView dequeueReusableCellWithIdentifier:TableViewCEll forIndexPath:indexPath];
if (Cell == nil) {
Cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewCEll];
}
UIImageView *imageView=[[UIImageView alloc]init];
imageView.frame =CGRectMake(5, 5, 100,110);
[Cell.contentView addSubview:imageView];
NSArray * array =[[self.ListOfCarArray objectAtIndex:indexPath.row]objectForKey:@"CarImage"];
if (array.count >0) {
NSString * str = [NSString stringWithFormat:@"%@uploads/Car/%@",[self.GetUserConfiDict objectForKey:@"server"],[[array objectAtIndex:0]objectForKey:@"name"]];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]init];
manager.responseSerializer = [AFImageResponseSerializer serializer];
[manager GET:str
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
imageView.image = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed with error %@.",[error localizedFailureReason]);
}];
}
UILabel * ModelLbl =[[UILabel alloc]initWithFrame:CGRectMake(120, 10, 120, 25)];
ModelLbl.textColor = [UIColor whiteColor];
NSDictionary *str = [[NSDictionary alloc]init];
str =[[self.ListOfCarArray objectAtIndex:indexPath.row]objectForKey:@"Car"];
ModelLbl.text = [str objectForKey:@"model"];
[Cell.contentView addSubview:ModelLbl];
int x = 120;
int y = 50;
for (int i = 1; i<=5; i++) {
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(x, y, 84,15)];
label.textColor = [UIColor whiteColor];
if (i ==1) {
id null = [str objectForKey:@"year"];
if ([null isKindOfClass:[NSNull class]]) {
label.text [email protected]"";
}
else{
label.text = [str objectForKey:@"year"];
[Cell.contentView addSubview:label];
}
}
else if (i == 2){
id null = [str objectForKey:@"color"];
if ([null isKindOfClass:[NSNull class]]) {
label.text [email protected]"";
}
else{
label.text =[str objectForKey:@"color"];
[Cell.contentView addSubview:label];
}
}
else if (i == 3){
id null = [str objectForKey:@"price"];
if ([null isKindOfClass:[NSNull class]]) {
label.text [email protected]"";
}
else{
label.text =[str objectForKey:@"price"];
[Cell.contentView addSubview:label];
x+=100;
y = 30;
}
}
else if (i ==4) {
id null = [str objectForKey:@"miles"];
if ([null isKindOfClass:[NSNull class]]) {
label.text [email protected]"";
}
else{
label.text =[str objectForKey:@"miles"];
[Cell.contentView addSubview:label];
}
}
else if (i == 5){
id null = [str objectForKey:@"stock_number"];
if ([null isKindOfClass:[NSNull class]]) {
label.text [email protected]"";
}
else{
label.text =[str objectForKey:@"stock_number"];
[Cell.contentView addSubview:label];
}
}
y+=20;
}
return Cell;
}