将字符串传递给另一个不起作用的视图

时间:2013-08-03 20:55:38

标签: ios objective-c uiviewcontroller

//FirstViewController.m

#import "EighthViewController.h"

EighthViewController *able = [[EighthViewController alloc] initWithNibName:@"EighthViewController" bundle:nil];
able.extra = @"dd"; //ERROR HERE----------------
[self presentViewController:able animated:YES completion:NULL];

//EighthViewController.h
@interface EighthViewController : UIViewController{
NSString *extra;
}

@property (nonatomic) NSString *extra;

每当我尝试使用此代码(来自here)时,我在FirstViewController中收到错误消息:Property 'extra' not found on object of type 'EighthViewController *'

1 个答案:

答案 0 :(得分:0)

您应该添加:

@property (nonatomic, retain) NSString *extra;

到您的EighthViewController.h文件。并添加以下内容:

@synthesize extra;

EighthViewController.m文件中。通常它应该工作

希望有所帮助