В моем приложении у меня есть ячейка в конце Tableview. При прокрутке это повторяется. Я использую пользовательскую ячейку на основе XIB. Последняя ячейка, повторяющаяся при прокрутке
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
if([self.invoiceList count] > 0)
{
return [self.invoiceList count]+1;
}
else
{
return [self.invoiceList count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"HistoryTableViewCell";
InvoiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"InvoiceTableViewCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
[self cellForTableView:tableView indexPathForCell:indexPath andInvoiceTableCell:cell];
return cell;
}
- (void)cellForTableView:(UITableView*)tableView indexPathForCell:(NSIndexPath *)indexPath andInvoiceTableCell:(InvoiceTableViewCell *)cell
{
//For displaying < END OF LIST >
if(indexPath.row == [self.invoiceList count])
{
cell.lblEndOfListOL.hidden = NO;
cell.lblItemOL.hidden = YES;
cell.lblDescriptionOL.hidden = YES;
cell.lblQuantityOL.hidden = YES;
cell.lblUOMOL.hidden = YES;
cell.imgViewCellVerticalOL1.hidden = YES;
cell.imgViewCellVerticalOL2.hidden = YES;
cell.imgViewCellVerticalOL3.hidden = YES;
}
//For Content cells
if([self.invoiceList count] > indexPath.row)
{
[self setValuesForCell:cell fromArray:self.invoiceList forIndex:indexPath.row];
}
}
- (void)setValuesForCell:(InvoiceTableViewCell*)cell fromArray:(NSMutableArray*)array forIndex:(NSInteger)index
{
// self.invoiceTableViewCellOL = cell;
if(showLess)
{
// First time load
self.imgViewVertical1OL.hidden = YES;
self.lblItemHeaderOL.hidden = YES;
cell.lblItemOL.hidden = YES;
cell.imgViewCellVerticalOL1.hidden = YES;
//Manage view
cell.lessCellView.hidden = false;
cell.moreCellView.hidden = true;
if(IS_IPHONE5_LANDSCAPE)
{
self.lessHeaderView.hidden = false;
self.lessHeaderView.layer.opacity = 1;
self.detailedHeaderView.hidden = true;
self.detailedHeaderView.layer.opacity = 0;
}
else
{
// Headers
cell.frame = CGRectMake(0,0,474,35);
self.lblDescriptionHeaderOL.frame = CGRectMake(0,45,95+9+195,35);
// Values
cell.lblItemOL.frame = CGRectMake(0,0,95,35);
cell.descriptionLbl.frame = CGRectMake(0,0,95+9+195,35);
cell.lblQuantityOL.frame = CGRectMake(308,0,75,35);
cell.lblUOMOL.frame = CGRectMake(390,0,82,35);
cell.imgViewCellVerticalOL1.frame = CGRectMake(95,-1,9,37);
cell.imgViewCellVerticalOL2.frame = CGRectMake(299,-1,9,37);
cell.imgViewCellVerticalOL3.frame = CGRectMake(383,-1,9,37);
}
}
else
{
self.imgViewVertical1OL.hidden = NO;
self.lblItemHeaderOL.hidden = NO;
cell.lblItemOL.hidden = NO;
cell.imgViewCellVerticalOL1.hidden = NO;
cell.lessCellView.hidden = true;
cell.moreCellView.hidden = false;
if(IS_IPHONE5_LANDSCAPE)
{
self.lessHeaderView.hidden = true;
self.lessHeaderView.layer.opacity = 0;
self.detailedHeaderView.hidden = false;
self.detailedHeaderView.layer.opacity = 1;
}
else
{
// Headers
cell.frame = CGRectMake(0,0,474,35);
self.lblItemHeaderOL.frame = CGRectMake(3,45,95,35);
self.lblDescriptionHeaderOL.frame = CGRectMake(107,45,195,35);
// Values
cell.lblItemOL.frame = CGRectMake(0,0,95,35);
cell.lblDescriptionOL.frame = CGRectMake(104,0,195,35);
cell.lblQuantityOL.frame = CGRectMake(308,0,75,35);
cell.lblUOMOL.frame = CGRectMake(390,0,82,35);
cell.imgViewCellVerticalOL1.frame = CGRectMake(95,-1,9,37);
cell.imgViewCellVerticalOL2.frame = CGRectMake(299,-1,9,37);
cell.imgViewCellVerticalOL3.frame = CGRectMake(383,-1,9,37);
}
}
if (array.count > index) {
if (!showLess) {
cell.lblDescriptionOL.text = [NSString stringWithFormat:@"%@",[[array objectAtIndex:index]objectForKey:@"Description"]];
}else {
cell.descriptionLbl.text = [NSString stringWithFormat:@"%@",[[array objectAtIndex:index]objectForKey:@"Description"]];
}
cell.lblItemOL.text = [NSString stringWithFormat:@"%@",[[array objectAtIndex:index]objectForKey:@"ItemID"]];
cell.lblQuantityOL.text = [NSString stringWithFormat:@"%@",[[array objectAtIndex:index]objectForKey:@"QtyShip"]];
cell.lblUOMOL.text = [NSString stringWithFormat:@"%@",[[array objectAtIndex:index]objectForKey:@"UOMDetails"]];
}
}
Предложите мне .. Спасибо
Ваше условие 'numberOfRowsInSection' и методы cellForRowAtIndexPath несовместимы. проверьте условия, которые вы должны будете использовать «[self.invoiceList count]> 0» и [self.invoiceList count]. –