-1

I am trying to pass an object from one view controller to another but it gives an error which is

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewController setTMode:]: unrecognized selector sent to instance 0x866ed70'
*** First throw call stack:
(0x250b022 0x2709cd6 0x250ccbd 0x2471ed0 0x2471cb2 0x28044 0x250ce99 0x155c14e 0x155c0e6 0x1602ade 0x1602fa7 0x1602266 0x15813c0 0x15815e6 0x1567dc4 0x155b634 0x2c0bef5 0x24df195 0x2443ff2 0x24428da 0x2441d84 0x2441c9b 0x2c0a7d8 0x2c0a88a 0x1559626 0x261d 0x2595)
terminate called throwing an exception

my method for the .h file is

@interface TransportViewController : UIViewController<UITextFieldDelegate>
{
    MapViewController *modeData;
    MapViewController *walkDistData;
    MapViewController *routeOptData;
    IBOutlet UITextField *tbMode;
    IBOutlet UITextField *tbWalkDist;
    IBOutlet UITextField *tbRouteOpt;
    IBOutlet UIPickerView *pickerView;
    NSMutableArray *modeArray;
    UITextField *activeField;
    IBOutlet UIButton *back;
}    

@property (retain, nonatomic) MapViewController *modeData;
@property (retain, nonatomic) MapViewController *walkDistData;
@property (retain, nonatomic) MapViewController *routeOptData;
@property (retain, nonatomic) IBOutlet UITextField *tbMode;
@property (retain, nonatomic) IBOutlet UITextField *tbWalkDist;
@property (retain, nonatomic) IBOutlet UITextField *tbRouteOpt;
@property (retain, nonatomic) IBOutlet UIButton *back;

- (IBAction) backAction:(id)sender;
@end

and this is the method i have for my .m file

- (void)viewDidLoad
{
    [super viewDidLoad];
    tbMode.delegate = self;
    tbWalkDist.delegate = self;
    tbRouteOpt.delegate = self;     
}
- (IBAction) backAction:(id)sender
{
    MapViewController *view=[[MapViewController alloc] initWithNibName:nil bundle:nil];
    self.modeData = view;
    self.walkDistData = view;
    self.routeOptData = view;
    // NSLog(@"%@", modeData); // this is where i test all the NSLog at
    modeData.tMode = tbMode.text;
    NSString *str = [tbWalkDist text];
    walkDistData.tWalkDist = [str intValue];
    routeOptData.tRouteOpt = tbRouteOpt.text;
    [self presentModalViewController:view animated:NO];

}

the error is caught in these lines

modeData.tMode = tbMode.text;
NSString *str = [tbWalkDist text];
walkDistData.tWalkDist = [str intValue];
routeOptData.tRouteOpt = tbRouteOpt.text;

I put a NSLog(@"%@", modeData); to check the values, it returns <MapViewController: 0x84627a0>

and NSLog(@"%@", tbMode.text); it return me the values A which is what I need.

*the error is with modeData.tMode & walkDistData.tWalkDist & routeOptData.tRouteOpt

What did I do wrong ? Please help . I can't seem to figure this one out

My second view controller .h

@interface MapViewController : UIViewController
{
    NSString *tMode;
    NSString *tRouteOpt;
    int tWalkDist;
} 
@property(nonatomic, retain)NSString *tMode;
@property(nonatomic, retain)NSString *tRouteOpt;
@property(nonatomic)int tWalkDist;
IronManGill
  • 7,222
  • 2
  • 31
  • 52
sihao
  • 273
  • 2
  • 5
  • 19
  • 3
    I think the error is that this line - `modeData.tMode = tbMode.text;` - should be this: `modeData.tbMode = tbMode.text;` because I don't see any property called `tMode` declared. – pasawaya Jul 31 '12 at 03:07
  • For tMode i declared in the sec view controller where i am passing the data to. which is `NSString *tMode; NSString *tRouteOpt; int tWalkDist;` – sihao Jul 31 '12 at 03:10
  • But did you declare them as properties? – pasawaya Jul 31 '12 at 03:11
  • yup all in the sec viewController which is the MapviewController. `@property(nonatomic, retain)NSString *tMode;` `@property(nonatomic, retain)NSString *tRouteOpt;` `@property(nonatomic)int tWalkDist;` – sihao Jul 31 '12 at 03:13
  • Could you post all the code for secViewController? Thanks. – pasawaya Jul 31 '12 at 03:14
  • Was your log for modeData in the same run as the error message you posted? I'm wondering because those 2 different logs show different instances of the MapViewController. – rdelmar Jul 31 '12 at 03:28
  • wat do u mean? i edited the code and place in the place where i use the NSLog at – sihao Jul 31 '12 at 03:30
  • You have 3 different mapViewController instances, and I'm wondering whether you're sending the setTMode message to the wrong one -- the error message shows instance 0x866ed70, whereas your log of modeData shows instance 0x84627a0. If these were both logged in the same run of the app, then these are two different instances. Should they be? – rdelmar Jul 31 '12 at 03:35

1 Answers1

1

You need to synthesize the tMode property in MapViewController.m:

@implementation MapViewController

@synthesize tMode;

...
rob mayoff
  • 375,296
  • 67
  • 796
  • 848