NSInvalidArgumentException错误

时间:2012-07-31 02:42:27

标签: iphone objective-c ios xcode4.3

我正在尝试将一个对象从一个视图控制器传递到另一个视图控制器,但它会出现错误

*** 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&amp; walkDistData.tWalkDist&amp; 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;

1 个答案:

答案 0 :(得分:1)

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

@implementation MapViewController

@synthesize tMode;

...