您好我有一個UITableView和我使用其中包含圖像的自定義單元格。當我重新加載UITableView它重新加載只是好的,但圖像不刪除我把它設置爲圖像爲零,並嘗試removeFromSuperView也沒有運氣。重新加載UITableview不會重新加載單元格中的圖像
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:identity];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity DefaultsArray:defaultColAndSpacesDict];
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
if([[dtaDictionary allKeys] count]!=0)
{
[cell.contentView clearsContextBeforeDrawing];
if([defaultsArray containsObject:@"Note"])
{
NSString *patNotes=[[currRow objectForKey:@"pat_notes"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *appNotes=[[currRow objectForKey:@"Notes"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if((![patNotes isEqualToString:@""] && patNotes!=nil) || (![appNotes isEqualToString:@""] && appNotes!=nil))
{
[cell.Note setBackgroundImage:[UIImage imageNamed:@"notes-green.png"] forState:UIControlStateNormal];
[cell.Note setBackgroundImage:[UIImage imageNamed:@"notes-green.png"] forState:UIControlStateHighlighted];
[cell.Note addTarget:self action:@selector(showNote:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
cell.Note.imageView.image=nil;
}
}
我調試了程序,它將nil賦值給它。我也試過ImageView的removeFromSuperView。可能是什麼問題呢?
注:Cell.Note是一個UIButton
在if條件添加斷點並檢查,確定條件總是成立。 – iPatel
嘗試[cell.Note setBackgroundImage:nil]; –
iPatel我嘗試使用斷點它分配爲零。 – Hassy