0

I have subclass of UITableViewCell. Here is my setup

enter image description here

I have used Autolayout. Now when user swipe on cell , I can see "Delete" button , but it overlaps my right side imageview. Cell contents are not shifting. Here is my code

    #pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.recentItemsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"ProductCell";
    ProductCell *cell = (ProductCell*)[tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil)
    {
        NSArray *cellArray = [[NSBundle mainBundle] loadNibNamed:@"ProductCell" owner:self options:nil];
        cell=[cellArray objectAtIndex:0];
        tableView.separatorColor = [UIColor clearColor];
    }

    Product *product = [self.recentItemsArray objectAtIndex:indexPath.row];
    cell.lblProductName.text = product.name;
    cell.lblNoOfBids.text = [NSString stringWithFormat:@"%@",product.numberOfBids];
    cell.lblBuyItNowPrice.text = [NSString stringWithFormat:@"%@ %@",CURRENCY_TYPE,product.buyItNowPrice];
    cell.lblTimeRemaining.text = product.timeRemaining;
    cell.lblLatestBid.text = [NSString stringWithFormat:@"%@ %@",CURRENCY_TYPE,product.currentBidPrice];
    cell.lblUserName.text = product.sellerName;

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 110.0f;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
        [CommonUtils showAlertWithTitle:@"Alert" andMessage:@"Do you want to delete this product?"];
    }
}

I saw several question on Stackoverflow , but didn't get any solution.

Can any body tell me what I am doing wrong ? Any kind of help is highly appreciated. Thanks

Update:: I tried adding UIImageView programatically. still image views are not shifting

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(260, 0, 50, 60)];
        imageView.backgroundColor = [UIColor yellowColor];
        [cell.contentView addSubview:imageView];


        UIImageView* imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(20.0, 0, 60, 60)];
        imageView1.backgroundColor = [UIColor redColor];
        [cell.contentView addSubview:imageView1];
    }

    //cell.textLabel.text = @"ABC";
    // Configure the cell...

    return cell;
}

enter image description here

Community
  • 1
  • 1
iOSAppDev
  • 2,755
  • 4
  • 39
  • 77

1 Answers1

0

It happend with me. Verify if some cell property have the same name from other property in the view where the UITableView is.

marceloquinta
  • 713
  • 12
  • 20