Когда я просматриваю свой пользовательский UITableviewCells, вы получаете неправильный контент (текст другой ячейки). Это происходит случайным образом. Я попробовал очистить ячейку, но потом у меня есть ячейка пробелов. Мой код ниже. Может ли кто-нибудь сказать мне, что происходит. Я прочитал много статей отсюда и в другом месте, что ячейку нужно очистить, но никто не работал для меня, поскольку я не уверен, в какой момент вы очищаете данные. Я даже пытался реализовать prepareForReuse в классе моей ячейки, но ничего хорошего.UITableviewCell отображает текст для другой ячейки при прокрутке
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self.products count] == 0) {
UITableViewCell *cell = [[UITableViewCell alloc] init];
return cell;
}
static NSString *CellIdentifier = @"AvailableCustomerProductCell";
AvailableCustomerProductTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.buttonAdd.tag = indexPath.row;
[cell.buttonAdd addTarget: self action: @selector(addToSelectedProduct:) forControlEvents: UIControlEventTouchUpInside];
Product *prod = nil;
if (theTableView == self.searchDisplayController.searchResultsTableView) {
prod = (Product *)[self.filteredProducts objectAtIndex:indexPath.row];
} else {
prod = (Product *)[self.products objectAtIndex:indexPath.row];
}
if (prod != nil) {
cell.pNumber.text = prod.number;
cell.description.text = prod.desc;
if ([Common getProductPromotion:prod] != nil) {
cell.btnPromotionTag.hidden = NO;
cell.btnPromotionTag.tag = indexPath.row;
[cell.btnPromotionTag addTarget: self action: @selector(showPromotionDetails:) forControlEvents: UIControlEventTouchUpInside];
}
else{
cell.btnPromotionTag.hidden = YES;
}
//Get the customer product price, first:
//If if the product has a record in the productCustomerPrices list
//if not get the price from the standard price.
if (self.order.orderOrderCustomer != nil) {
CustomerPrice *custPrice = [Common getPriceForCustomer:self.order.customerRef forProduct:prod.productId];
if (custPrice != nil) {
//get the customer price
[cell.btnPrice setTitle:[Common getCurrencyFormattedStringFromFloat:[custPrice.price floatValue]] forState:UIControlStateNormal];
[cell.btnPrice setTitleColor:[UIColor colorWithRed:0.01 green:0.65 blue:0.77 alpha:1] forState:UIControlStateNormal];
cell.btnPrice.enabled = NO;
}else{
//get the standard price
float price =[[Common GetProductStandardPrice:prod.productStanddardPrices ByQuantity:[NSNumber numberWithInt:1]] floatValue];
[cell.btnPrice setTitle: [Common getCurrencyFormattedStringFromFloat:price] forState:UIControlStateNormal ];
[cell.btnPrice setTitleColor:[UIColor colorWithRed:1.0 green:0.39 blue:0.0 alpha:1] forState:UIControlStateNormal];
cell.btnPrice.tag = indexPath.row;
[cell.btnPrice addTarget: self action: @selector(showStandardPrices:) forControlEvents: UIControlEventTouchUpInside];
cell.btnPrice.enabled = YES;
}
}
}
UISwipeGestureRecognizer* sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwiped:)];
[sgr setDirection:UISwipeGestureRecognizerDirectionRight];
[cell addGestureRecognizer:sgr];
return cell;
}
Какой объекта, текст не исчезает? – rebello95
BTW вы должны добавить распознаватель жестов внутри подкласса ячейки, а не в cellForRow – rounak
Целевой метод находится на контроллере представления. Слишком много хлопот, чтобы вызвать его из ячейки, насколько я знаю. –