1

I have a strange error . I am using UITableView which has to be reloaded when a row get selected . This works fine in iPhone simulator . While running in iPad , didSelectRowAtIndexPath is getting called but the UI isn't getting updated . I tried calling the method reloadData on main thread . It's still the same .

I have tried various solutions in stackoverflow . Nothing seemed to fix my issue .

UPDATE

When i select a cell , new cell will be added . So i need to reload my tableview to display the dynamic change . Posted my code below

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
NSUInteger count=indexPath.row+1;

NSMutableArray *insertIndexPaths = [NSMutableArray array];

[insertIndexPaths addObject:[NSIndexPath indexPathForRow:count inSection:indexPath.section]];

switch (indexPath.row) {
        case 0:
    {
    if ([ItemsInSection[indexPath.section] count]==1){
                [ItemsInSection[indexPath.section] addObject:obj2];

                [TabView beginUpdates];
                [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];

                [TabView endUpdates];        
            }
            else {

                [ItemsInSection[indexPath.section] removeAllObjects];
                [ItemsInSection[indexPath.section] addObject:obj1];

                [self.TabView reloadData];

            }
        }
            break;

        case 1:

    {if ([ItemsInSection[indexPath.section] count]==2){
                [ItemsInSection[indexPath.section] addObject:obj3];

                [self.TabView beginUpdates];
                [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
                [self.TabView endUpdates];

            }
            else
            {
                [ItemsInSection[indexPath.section] removeAllObjects];
                [ItemsInSection[indexPath.section] addObject:obj1];
                [ItemsInSection[indexPath.section] addObject:obj2];

                [self.TabView reloadData];
              }
        }
            break;

        case 2: {

            if ([ItemsInSection[indexPath.section] count]==3) {
                 [ItemsInSection[indexPath.section] addObject:obj4];
                [self.TabView beginUpdates];
                 [TabView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
                [self.TabView endUpdates];

            }
            else
            {
                [ItemsInSection[indexPath.section] removeObject:obj4];
                [self.TabView beginUpdates];
                 [TabView deleteRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];

                [self.TabView endUpdates];

            }
          }
            break;

                  default:
            break;
    }

}
user5553647
  • 199
  • 2
  • 13
  • 2
    You should post your code. It sounds to me the problem is somewhere else. Besides, why do you want to reload entire table view when you select a cell? Please describe the actual goal you are trying to achieve instead of looking for a solution for a not working attempt of yours. – Ozgur Vatansever May 14 '16 at 07:11

2 Answers2

2

You are reloading table view inside table view delegate, On tableview selection delegate method have their associated selection animation process. So I will suggest you to move all code inside this method to separate method. and call that method.

   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(),^{
          [self.aiTableView beginUpdates];
          // your table view selection code
          [self.aiTableView endUpdates];
     });  
kaushal
  • 1,553
  • 18
  • 25
  • This doesn't fix my issue . NumberOfRowsInSection methods returns no.of rows . But it is not getting inserted in UITableView . This happens only in iPad . My original code works well in iPhone . I'm wondering what could be the issue – user5553647 May 17 '16 at 05:17
  • Please try by moving all my code from dispatch_after() in to dispatch_async(dispatch_get_main_queue(), ^{ }); , make sure you are out of table view delegate selection method the time this block of code call. – kaushal May 17 '16 at 05:38
  • I am not sure about the behaviour of your code with iPhone and iPad. :) – kaushal May 17 '16 at 05:40
0

I have found the solution for this issue . The background color of UITableViewCell was set to clear colour and the background color of UIView on the UITableViewCell was also set to clear colour . Changing these settings displayed the insertion of rows in UITableView in iPad simulator .

user5553647
  • 199
  • 2
  • 13