UA-17470720-3

Jump to content


Photo
- - - - -

Populating first item on iPad after reading objects from store


  • Please log in to reply
12 replies to this topic

#1 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 07 April 2013 - 01:32 PM

After reading objects into the master list, how can I automatically populate the detail table (as if the user tapped the first item in the list)?

Bruce
  • hwf9vjkj8s2 likes this

#2 Dave Guerin

Dave Guerin

    Forum Master

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

Posted 07 April 2013 - 10:41 PM

Hi Bruce,

Try this:

[yourSection dispatchEventSelectRowAtIndexPath:yourIndexPath];

HTH
  • Tarek likes this
Cheers,

Dave

www.dgapps.ie

#3 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 29 April 2013 - 08:15 AM

Hi Bruce,

Try this:

[yourSection dispatchEventSelectRowAtIndexPath:yourIndexPath];

HTH


This doesn't work unfortunately.

Using a UISplitViewController, this ends up putting the detail view in the same pane as the master view.

#4 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 12 May 2013 - 11:01 AM

Tarek - anything on this?

#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 May 2013 - 05:40 PM

Hi Bruce,

 

Is your master view controller connected to the detail view controller via masterViewController.tableViewModel.detailViewController = detailViewController ?



#6 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 19 May 2013 - 04:00 PM

Tarek,

Yes, it is.

I wonder if the issue is that when I am building the model I typically instantiate an SCArrayOfObjectsModel and then set self.tableViewModel to that.

Bruce

#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 29 May 2013 - 11:47 AM

Hi Bruce,

 

I can check the project for you if you wish. Please create a new support ticket and attach it there. Thanks.



#8 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 16 August 2013 - 01:54 AM

Tarek,

 

Anything on this? It's been almost a month now since I created the support ticket as you requested.

 

Bruce



#9 CHAU LE

CHAU LE

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 32 posts
Reputation: 2
Good

Posted 18 August 2013 - 05:51 AM

This happens to me too.

 

Please advise Tarek.



#10 Bruce Vander Werf

Bruce Vander Werf

    Sr. Member

  • STV 5.0 Pro
  • PipPipPip
  • 30 posts
Reputation: 7
Good

Posted 06 September 2013 - 06:05 PM

Tarek - anything on this?

#11 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 07 September 2013 - 12:22 AM

Greetings Programs!

 

I've been messing around with the sample iPad App trying to find some way to do it and I sort of have it displaying (but other things break)...

 

This isn't a solution or even remotely close to one but it could be a starting point for a workaround...

 

RootViewController.h

#import "DetailViewController.h"

@interface RootViewController : SCTableViewController

@property(nonatomic) BOOL isFirstLoad;
@property(nonatomic, strong) DetailViewController *detailViewController;

@end

 

RootViewController.m

    // Create a weak instance of self to be used within the blocks.
    __weak typeof(self) weak_self = self;
	self.isFirstLoad = YES;
	self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];

	objectsSection.sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
	{
		NSLog(@"detailModelWillPresent");
		NSLog(@"detailModel: %@", detailModel);
		if (weak_self.isFirstLoad) {
			[[weak_self.detailViewController navigationController] popViewControllerAnimated:NO];
			[[weak_self.detailViewController navigationController] pushViewController:detailModel.viewController animated:YES];
			weak_self.isFirstLoad = NO;
		}
		else
		{
			weak_self.tableViewModel.detailViewController = detailModel.viewController;
		}
	};
	
	[self.tableViewModel addSection:objectsSection];
	
	if (self.isFirstLoad) {
		[objectsSection dispatchEventSelectRowAtIndexPath:(NSIndexPath *)[[self.tableView indexPathsForVisibleRows] objectAtIndex:0]];
	}

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 17 September 2013 - 02:32 PM

Hi Bruce,

 

I checked your app and it turns out that the DetailViewController didn't get the chance to load by the time MasterViewController appeared. This can be easily rectified by waiting by a really small interval (1/10 second is way more than enough) before dispatching the event. Here is a code sample that should work once added to your MasterViewController:

 

 

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
   
    [self performSelector:@selector(selectFirstRow) withObject:nil afterDelay:0.1];
}

- (void)selectFirstRow
{
    SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel sectionAtIndex:0];
    if(objectsSection.items.count)
    {
        NSIndexPath *firstRowIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.tableViewModel.tableView selectRowAtIndexPath:firstRowIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
        [objectsSection dispatchEventSelectRowAtIndexPath:firstRowIndexPath];
    }
}

 

Please confirm that this is working.


Edited by Tarek, 17 September 2013 - 02:37 PM.


#13 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 17 September 2013 - 02:45 PM

Alternatively, you can also dispatch the event from DetailViewController itself (which might be an even better solution). Just place the following code in your DetailViewController:

 

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
   
    if(self.tableViewModel.masterModel)
    {
        SCArrayOfObjectsSection *objectsSection = (SCArrayOfObjectsSection *)[self.tableViewModel.masterModel sectionAtIndex:0];
        if(objectsSection.items.count)
        {
            NSIndexPath *firstRowIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
            [self.tableViewModel.masterModel.tableView selectRowAtIndexPath:firstRowIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
            [objectsSection dispatchEventSelectRowAtIndexPath:firstRowIndexPath];
        }
    }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users