UA-17470720-3

Jump to content


Photo
- - - - -

dispatchEventSelectRowAtIndexPath to drill down more than once...


  • Please log in to reply
3 replies to this topic

#1 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 29 November 2013 - 05:13 AM

Hi all,

 

I have a STV Core Data app, RootEntity each with multiple ChildEntity, and each of the ChildEntity have multiple MediaEntity.

 

I'm able to export the MediaEntity file, and a plist with all the Core Data, er, data to a ZIP file.

 

I'm able to import the ZIP file, extract the MediaEntity file and place it in the correct place, and extract the plist and add the data back into Core Data. STV shows all the imported data as expected.

 

What I'm having problems with is automatically drilling down to the newly imported MediaEntity. If there are no other RootEntity it all works. If there is an existing RootEntity, wether it's the owner of the importing MediaEntity tor not, then I seem to get stuck in a orphan ChildEntity where selecting the cell just redisplays the same ChildEntity instead of the MediaEntity. Going back eventually crashes with a "Can't add self as a subView" error.

 

Here's the code to dispatch to the MediaEntity:

 

SCArrayOfObjectsSection *mediaItemsSection = (SCArrayOfObjectsSection *)[self.tableViewModel.activeDetailModel.activeDetailModel sectionAtIndex:1]; // The 2nd section has the MediaEntity

    MediaEntity *loopMediaItem;
    for (long i = 0; i < [mediaItemsSection.items count]; i++) {
        loopMediaItem = (MediaItemEntity *)[mediaItemsSection.items objectAtIndex:i];

        if ([loopMediaItem.mediaItemGUID isEqualToString:mediaItemEntity.mediaItemGUID]) {
            NSLog(@"DISPATCH:%li",i);

            double delayInSeconds = 0.625;
            dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
            dispatch_after(when, dispatch_get_main_queue(), ^(void){
                [mediaItemsSection dispatchEventSelectRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:1]];
            });

            goto mediaItemDispatched;
        }
        loopMediaItem = nil;
    }
    NSLog(@"NOT DISPATCHED!");
mediaItemDispatched:
 

 

 The delays are in there to allow STV time to create the activeDetailModel before I then call dispatchEventSelectRowAtIndexPath on that model.

 

As I say, it all works when there's no RootEntity to start with, but breaks otherwise.

 

Anyone else done anything similar? Any pointers? Comments?

 


Cheers,

Dave

www.dgapps.ie

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 03 December 2013 - 02:50 PM

Hi Dave,

 

Are you adding the delays just for STV, or do you actually need your app to animate the drill down?



#3 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 04 December 2013 - 06:18 AM

Hi Tarek,

 

Yes, the delays were just for STV, and showing the animation isn't a necessity, although it does show the user what's happening.

 

If all the data is already in STV, then I can successfully programatically drill down to RootEntity 1 > ChildEntity 2 > MediaEntity 3, using the delays, then popToRootViewControllerAnimated, then drill down RootEntity 0 > ChildEntity 4 > MediaEntity 3, popToRootViewControllerAnimated, drill down to RootEntity 2 > ChildEntity 6 > MediaEntity 0, and so on, and keep doing that all afternoon without problems.  I haven't (yet) experimented with minimum delay times.

 

I think because in my current code I was sometimes inserting the Entity just before selecting it with dispatchEventSelectRowAtIndexPath that was causing some issues somewhere.

 

What I think I'm going to do with this now is insert all the Entity into Core Data as required, reordering each section as I go to place my new item at position 0, and then drill down RootEntity 0 > ChildEntity 0 > MediaEntity 0 using slight delays.

 

Unless there's another more elegant way!


Cheers,

Dave

www.dgapps.ie

#4 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 137
Popular

Posted 20 December 2013 - 01:42 AM

If anyone is interested, I did get this working by popToRootViewControllerAnimated, adding all the data to Core Data and reordering all the current data so that my new Entity was at position 0  in each table, showing a UI blocking activity indicator, reloading the root tableView, and then dispatchEventSelectRowAtIndexPath to drill down RootEntity 0 > ChildEntity 0 > MediaEntity 0 using a delay of 1 second between dispatchEventSelectRowAtIndexPath which was long enough even on a iPhone 3GS, and finally removing my activity indicator.

 

The only slight issue I had was that I have a placeholderCell for the RootEntity that was half the height of the normal RootEntity cells. If the placeholderCell was visible when importing the new entity, then the resultant RootEntity cell was vertically truncated. Making the placeholderCell the same height as the RootEntity got around that. That was an iOS7 issue only, iOS6 was fine.


Cheers,

Dave

www.dgapps.ie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users