views:

5068

answers:

8

i'm having a hard time with Xcode; for some reason, it just won't let me pass a variable from one view controller class to another. It should work, i was basically just copying/pasting from my other classes (it works on all of them... except this one). I've been at it all night long, tried everything i could think of and still it remains.

Here's the view controller class where I'm making the call:

ResultadosViewController.h:

#import <UIKit/UIKit.h>
#import "Filme.h"
#import "Festival.h"
#import "Top10Discos.h"
#import "Peca.h"

@class DetalhesViewController;

@interface ResultadosViewController : UIViewController
{
    // Navegation
    DetalhesViewController *dvc;
    BOOL isViewPushed;

    // What i'd really like to pass lol
    NSArray *array_resultados;

}

@property (nonatomic, retain) NSArray *array_resultados;
@property (nonatomic, readwrite) BOOL isViewPushed;

@end*

ResultadosViewController.m:

#import "ResultadosViewController.h"
#import "DetalhesViewController.h"
#import "Filme.h"
#import "Peca.h"
#import "Top10Discos.h"
#import "Festival.h"

@implementation ResultadosViewController
@synthesize isViewPushed, array_resultados;

(...)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

    if (indexPath.row == 2)
    {
     if(dvc != nil)
      [dvc dealloc];

     NSString *ffs = [[array_resultados objectAtIndex:indexPath.row] TituloFilme];

     dvc = [[DetalhesViewController alloc] initWithNibName:@"DetailedView" bundle:[NSBundle mainBundle]];

     **resultadosControllerCell.array_resultados  = [self array_resultados];** 
     *"Request for member 'array_resultados' in something not a structure or union"*

     //Push the view controller to the top of the stack.
     [self.navigationController pushViewController:dvc animated:YES];

    }
}

And here's the other class i want to send the array into:

DetalhesViewController.h:

#import <UIKit/UIKit.h>

#import "Filme.h"
#import "Festival.h"
#import "Top10Discos.h"
#import "Peca.h"


@interface DetalhesViewController : UIViewController
{
    // Navegacao
    NSArray *array_resultados;

}

@property (nonatomic, retain) NSArray *array_resultados;
@end

I'm not sure if any of you would to see the .m file for this class; in that case, just ask.

Thanks in advance, Hal

PS: tried with other variables (other types too), cleansed/rebuilt, recreated xib file, you name it... i'm outta tricks :(

+2  A: 

Just a guess, but did you try using the arrow operator -> instead of the dot operator . ?

resultadosControllerCell->array_resultados  = [self array_resultados];
Adam Rosenfield
A: 

is resultadosControllerCell a valid object in the ResultadosViewController class?

Abizern
+2  A: 

This doesn't exaclty answer your question, but your memory management is a bit wonky. This line:

[dvc dealloc];

should read like this:

[dvc release];
dvc = nil;

In Cocoa, you should never call dealloc directly -- follow the retain/release/autorelease pattern and things will work better and as intended.

Matt Ball
A: 

Thanks for all your answers, trying now :)

A: 

Ok, i just swapped every [dealloc] por releases and nils; no change. As for the arrow operator, i'm assuming you mean

dvc->array_resultados = [self array_resultados];

Because we're already in the ResultadosViewController class. Either way, it simply says: "struct DetalhesViewController has no member named 'array_resultados'!

As for the valid object, i believe so... would i be able to see the table if it wasn't?

How is this possible..? Now that i notice it, yeah the code completion won't work. I have no idea on what's going on :(

A: 

Ok i've had it; using a cheap trick to show the info:

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:ffs message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    UILabel *myTextField = [[UILabel alloc] init];
    myTextField.text = @"FFS!";
    CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
    [myAlertView setTransform:myTransform];

    [myTextField setBackgroundColor:[UIColor whiteColor]];
    [myAlertView addSubview:myTextField];
    [myAlertView show];
    [myAlertView release];

Really hate using this, but i'm already a day late. I should have delivered it by yesterday.

Thanks for your help guys, if you happen to find the solution please let me know. You never know if it'll happen again :/

Cheers!

+4  A: 

First off, don't use -> — that's direct instance-variable access. It may work, but you're changing another object's instance variables without its knowledge, which is just asking for trouble.

And no, Adam Rosenfield didn't mean dvc->array_resultados; he meant resultadosControllerCell->array_resultados, which is what he said and which he based on what you said.

The correct solution is a blend of your original line and your revision of Adam's line:

dvc.array_resultados = [self array_resultados];

This goes through the property you declared in the DetalhesViewController class.

Speaking of which, you should declare that property as copy, not retain. Otherwise, you'll find yourself holding somebody else's mutable array, which they will then modify—more bad mojo.

Peter Hosey
A: 

Hal,

Can you add the .m file? I am trying to pass variables between classes too except I want to use NSString instead of NSArray. I don't know how to retrieve the info from the NSString in the .m file.

Thanks