-1

我试图将一个对象从一个视图控制器传递到另一个视图控制器,但它给出了一个错误,即

*** 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

我对 .h 文件的方法是

@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

这就是我的 .m 文件的方法

- (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];

}

错误在这些行中被捕获

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

我放了一个NSLog(@"%@", modeData);来检查值,它返回<MapViewController: 0x84627a0>

NSLog(@"%@", tbMode.text);返回我A需要的值。

*错误是modeData.tMode& walkDistData.tWalkDist&routeOptData.tRouteOpt

我做错了什么 ?请帮忙 。我似乎无法弄清楚这个

我的第二个视图控制器 .h

@interface MapViewController : UIViewController
{
    NSString *tMode;
    NSString *tRouteOpt;
    int tWalkDist;
} 
@property(nonatomic, retain)NSString *tMode;
@property(nonatomic, retain)NSString *tRouteOpt;
@property(nonatomic)int tWalkDist;
4

1 回答 1

1

您需要在中合成tMode属性MapViewController.m

@implementation MapViewController

@synthesize tMode;

...
于 2012-07-31T03:43:13.473 回答