Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
in TableView.m:

Code:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *selectedCell = cell.textLabel.text;
    NSLog(@"Toon mij het extra venster om details weer te geven/aan te passen van: %@", selectedCell);
    
    if(buttonPushed == @"Goals"){
        
        GoalDetailViewController *goalDetail = [[GoalDetailViewController alloc] initWithNibName:@"GoalDetailViewController" bundle:[NSBundle mainBundle]];
        goalDetail.context = context;
        goalDetail.title = goalDetail.goal.goalNaam;
        
        
        Goal *goal = [arr objectAtIndex:indexPath.row];
        goalDetail.goal = goal;
        
        [self.navigationController pushViewController:goalDetail animated:YES];

When I tap the accessorybutton, I want a detailview to be loaded with the data from the selected cell.
Loading the attributes from the Goal entity is not a problem

Code:
descriptionField.text = goal.goalDescription;
nameTextField.text = goal.goalName;

but I want to load the relationships too..
But how do I get an object out of the NSSet ?
And how can I turn it into a NSString?
Is this possible in the same way as I load the description and name attributes? Or do I need a fetch request ?
 

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
Please tell me if my question is not clear ...Really want an answer on this one.
 
Last edited by a moderator:

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Please tell me if my question is not clear ...Really want an answer on this one.

Your question is not clear.

What set are you talking about?

NSSet objects are not usually used in the data source for a table view because sets are "unordered collections". The items in a set are not saved in any particular order.

You need to explain your data structures, where you are using an NSSet and what you are using it for. Then you need to explain what you are trying to do with that set. Only then will we be able to help you.
 

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
in Goal.h

Code:
@property (nonatomic, retain) NSString * goalBeschrijving;
@property (nonatomic, retain) NSString * goalId;
@property (nonatomic, retain) NSString * goalNaam;
@property (nonatomic, retain) NSSet *responsibility;

- (void)addResponsibilityObject:(Actor *)value;
- (void)removeResponsibilityObject:(Actor *)value;
- (void)addResponsibility:(NSSet *)values;
- (void)removeResponsibility:(NSSet *)values;


in TableView.m (can be seen as a MasterView)


Code:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *selectedCell = cell.textLabel.text;
    NSLog(@"Toon mij het extra venster om details weer te geven/aan te passen van: %@", selectedCell);
    
    if(buttonPushed == @"Goal"){
        
        GoalDetailViewController *goalDetail = [[GoalDetailViewController alloc] initWithNibName:@"GoalDetailViewController" bundle:[NSBundle mainBundle]];
        
        goalDetail.context = context;
        goalDetail.title = goalDetail.goal.goalNaam;
        
        Goal *goal = [arr objectAtIndex:indexPath.row];
        goalDetail.goal = goal;
        
        [self.navigationController pushViewController:goalDetail animated:YES];

in GoalDetailViewController.m (DetailView)

Code:
-(void)viewWillAppear:(BOOL)animated{
    
   
    [self setTitle:goal.goalNaam];
    beschrijvingField.text = goal.goalBeschrijving;
    nameTextField.text = goal.goalNaam;
   
    if([goal.responsibility count] > 0)
        {
            actoren = [[NSArray alloc] init];
    
            actoren  =  [goal.responsibility allObjects]  ;
           responsibleField.text = [actoren objectAtIndex:0];

With the last line of code, I get an error, something which is normal because I want to put an object into a textfield.. that's where's my problem...

Responsibility is the relationship between an Actor-entity and a Goal-entity (using Core Data).
In general, when a relationship is added to a NSSet, (in this case a Responsibility of an Actor over a Goal) how can i retrieve the corresponding Actor, using a Goal object..
I hope my question is clear now
 
Last edited by a moderator:

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
What error? Compile-time or run-time? Etc.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Actor _isNaturallyRTL]: unrecognized selector sent to instance 0x6b36bf0'
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
With the last line of code, I get an error, something which is normal because I want to put an object into a textfield.. that's where's my problem...

Only a text string can go into a textfield. Please explain how an Actor object is a text string, and can go into a textfield.

Analogy: A 1-liter glass jar can contain fruit. Cherries are fruit. Cherries can go into the jar. This does not mean you can chop down a cherry tree and put the entire tree into the jar.

Something you get from the tree can go into the jar. Likewise, something you get from the Actor object can go into the textfield. What is it? A name? A description? Something else?

Saying you want the entire Actor object in the textfield is nonsense, in the same way that putting an entire cherry tree into a 1-liter jar is nonsense.


Responsibility is the relationship between an Actor-entity and a Goal-entity (using Core Data).
In general, when a relationship is added to a NSSet, (in this case a Responsibility of an Actor over a Goal) how can i retrieve the corresponding Actor, using a Goal object..
I hope my question is clear now
This question has nothing to do with your problem. Please explain how getting a Goal object is related to putting a text string into a textfield. Is there something you get from a Goal object that you want to go into the textfield? What? Its name? Something else?
 
Last edited:

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
That's where's my problem .. I want the name of Actor (actorNaam) into the textfield. My title: How to get an object from a NSSet into a NSString ..

In the same way I put the name (goalNaam) and a description (goalBeschrijving) into a textfield, I want to put the name of the actor (actorNaam) that's connected with a relationship, Responsibility with a Goal, into a textfield ...

Like this:
beschrijvingField.text = goal.goalBeschrijving;
nameTextField.text = goal.goalNaam;




This is the code where I add the Goal and the Responsible Actor:

Code:
    Goal *addgoal = (Goal*)[NSEntityDescription insertNewObjectForEntityForName:@"Goal" inManagedObjectContext:context];
        
        addgoal.goalNaam = nameTextField.text;
        addgoal.goalId = idField.text;
        addgoal.goalBeschrijving = beschrijvingField.text;
       
        Actor *actor = (Actor*)[NSEntityDescription insertNewObjectForEntityForName:@"Actor" inManagedObjectContext:context];
         
        actor.actorNaam = responsibleField.text;
        
        NSLog(@"Actor %@ toegevoegd", responsibleField.text);
        
        [addgoal addResponsibilityObject:actor];

My first question: is this the right way to add it?
My second question: how can i retrieve the actorNaam (name of the actor, NSString) from the NSSet (responsibility)?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
Post the code that actually adds objects to the NSSet named 'responsibility'. You haven't shown any code that adds objects to any NSSet, so how are we supposed to know what types of objects are in the NSSet? All you've posted is this:
Code:
        [addgoal addResponsibilityObject:actor];
You haven't shown any implementation of addResponsibilityObject: .


What are the types of objects in the NSSet named 'responsibility'? If the type is Actor, then show the @interface of that class. If you intend to add the name of an Actor to a textfield, then how would we know how to get its name? We don't know what its properties or instance variables are.

If the NSSet contains Actor objects, and there is a method or property that returns its name as NSString, then it's a simple matter of following one object (the NSSet) to another object (the Actor) to the object that goes into the textfield (an NSString). You were able to do that for the Goal object, so the same logic applies.

If the problem is you don't know how to get the correct Actor object from the NSSet, then you should explain why you decided to use NSSet. A different collection class might be more appropriate. If you've chosen the wrong collection class, it will be difficult or impossible to get it working effectively.
 

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
I thought an autogenerated accessor (CoreDataGeneratedAccessors) didn't require an implementation, .. so it does ?

If the NSSet contains Actor objects, and there is a method or property that returns its name as NSString, then it's a simple matter of following one object (the NSSet) to another object (the Actor) to the object that goes into the textfield (an NSString). You were able to do that for the Goal object, so the same logic applies.

I've got no method that returns its name as NSString .. I don't know how to do that, that's my main question.


Additional information:
In my masterview, when i call my detailview
Code:
        GoalDetailViewController *goalDetail = [[GoalDetailViewController alloc] initWithNibName:@"GoalDetailViewController" bundle:[NSBundle mainBundle]];
        
        goalDetail.context = context;
        goalDetail.title = goalDetail.goal.goalNaam;
        
        Goal *goal = [arr objectAtIndex:indexPath.row];
        goalDetail.goal = goal;
 

phr0ze

macrumors 6502a
Jun 14, 2012
513
0
Columbia, MD
I've never coded Objective C yet. So don't shoot me, but is this your answer?

Code:
-(void)viewWillAppear:(BOOL)animated{
    
   
    [self setTitle:goal.goalNaam];
    beschrijvingField.text = goal.goalBeschrijving;
    nameTextField.text = goal.goalNaam;
   
    if([goal.responsibility count] > 0)
        {
            actoren = [[NSArray alloc] init];
    
            actoren  =  [goal.responsibility allObjects];
            Actor *actor = (Actor*)[actoren objectAtIndex:0];
           responsibleField.text = actor.actorNaam;
 

Fuzej

macrumors newbie
Original poster
Jul 20, 2012
12
0
I've never coded Objective C yet. So don't shoot me, but is this your answer?

Code:
-(void)viewWillAppear:(BOOL)animated{
    
   
    [self setTitle:goal.goalNaam];
    beschrijvingField.text = goal.goalBeschrijving;
    nameTextField.text = goal.goalNaam;
   
    if([goal.responsibility count] > 0)
        {
            actoren = [[NSArray alloc] init];
    
            actoren  =  [goal.responsibility allObjects];
            Actor *actor = (Actor*)[actoren objectAtIndex:0];
           responsibleField.text = actor.actorNaam;

This is indeed possibly the answer I was looking for. Thanks for the effort :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.