UA-17470720-3

Jump to content


Photo
- - - - -

How to pass info stored in Web Model to Detail View Controller

models data-stores

  • Please log in to reply
5 replies to this topic

#1 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 23 June 2014 - 12:48 PM

I know how to do this if I build a table view off an array of objects or using SC Core Data but not sure with web model. How does it store the object from a web service in the index path so I can extract it into my detail view? See my code below. The "Fake User" string transfers correctly. the userId and activityIDD I check with NSLog both return null. How would I extract the property "UserName" in my web model for the indexPath?

 

    webSection.sectionActions.detailViewControllerForRowAtIndexPath = ^UIViewController*(SCTableViewSection *section, NSIndexPath *indexPath)

   {

        ActivityViewController *customVC = [[ActivityViewController alloc] initWithNibName:@"ActivityView" bundle:nil];

       self.userIds = [NSMutableDictionary dictionary];

 

       id userId = [self.userIds objectForKey:indexPath];

       NSString *activityIDD = [userId objectForKey:@"UserName"];

       NSLog(@"%@",userId);

       NSLog(@"%@",activityIDD);

 

        customVC.myActivityID = @"Fake User";

        return customVC;    };


Edited by rolfenstein, 23 June 2014 - 12:59 PM.

  • alogorpaPef likes this

#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 23 June 2014 - 05:03 PM

Hi

 

first is to never use "self" references within blocks.. do a search for weak self in the forums to get an idea of how to correct your code

 

as for the NSLogs writing out null.. the obvious reason for this is that nothing is ever added to self.userIds in your code.. all you have is the initialiser self.userIds = [NSMutableDictionary dictionary];

right after this you try to set id userId by pulling an objectForKey from an empty mutable dictionary 

 

Oz


  • rolfenstein likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 23 June 2014 - 08:31 PM

Thanks Oz. Actually please ignore that part of the code. I am just trying to copy out of http://www.appdesign.../sensibleshare/

 

My question is not so much "what is wrong with my code" as "how do I do this in STV"

 

In non STV I would do something like this

 

[self.dataModel setIndexOfSelectedChecklist:indexPath.row];

User *user = self.dataModel.users[indexPath.row];

[self performSegueWithIdentifier:@"ShowUser" sender:user];

 

How to call the object at the index path in STV Web model? So code inside sectionActions.detailViewControllerForRowAtIndexPath is considered a block? I still don't fully understand the difference between blocks and non blocks.



#4 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 24 June 2014 - 02:48 AM

how about

webSection.sectionActions.detailViewControllerForRowAtIndexPath = ^UIViewController*(SCTableViewSection *section, NSIndexPath *indexPath)
    {
        
        ActivityViewController *customVC = [[ActivityViewController alloc] initWithNibName:@"ActivityView" bundle:nil];
        
        User *userId = (User*)[[section cellAtIndex:indexPath.row] boundObject];

        NSString *activityIDD = userId.UserName;
        NSLog(@"%@",userId);
        NSLog(@"%@",activityIDD);
        
        customVC.myActivityID = @"Fake User"; //now insert object here
        return customVC;
    };


  • rolfenstein likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#5 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 24 June 2014 - 09:52 PM

But the web model is not mapped to an object so how could this work? UserName is the key in the JSON dictionary returned from the website, username is the NSSting property in both my User and Activity objects.

 

Get this error with what you have (except using the Activity object instead of user and using the correct property name username:

 

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM username]: unrecognized selector sent to instance 0x15e4dbb0'



#6 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 25 June 2014 - 10:03 PM

Ok I got it to work. I used Oz's code but declare userId as an NSDictionary rather than an Object. Thanks. In the process noticed that userId is storing all the JSON key items, not just the ones I mapped to my web section, which makes it easier for me. 

 

webSection.sectionActions.detailViewControllerForRowAtIndexPath = ^UIViewController*(SCTableViewSection *section, NSIndexPath *indexPath)

   {

        ActivityViewController *customVC = [[ActivityViewController alloc] initWithNibName:@"ActivityView" bundle:nil];

 

        NSDictionary *userId = (NSDictionary*)[[section cellAtIndex:indexPath.row] boundObject];

       NSString *activityIDD = [userId objectForKey:@"UserName"];

       NSLog(@"%@",userId);

       

       NSLog(@"%@",activityIDD);

 

       customVC.myActivityID = activityIDD;

 

        return customVC;    };







Also tagged with one or more of these keywords: models, data-stores

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users