Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:在ViewController类型的对象上找不到属性_Ios_Objective C_Xcode - Fatal编程技术网

iOS:在ViewController类型的对象上找不到属性

iOS:在ViewController类型的对象上找不到属性,ios,objective-c,xcode,Ios,Objective C,Xcode,所以我试图在另一个视图控制器NewLinkViewController中设置一个浮点值 这是我的密码: - (IBAction)selectSize:(id)sender { UIButton *selectSize = (UIButton *) sender; sizeChosen = [[[selectSize titleLabel] text] floatValue]; [self dismissViewControllerAnimated:YES completion:^{

所以我试图在另一个视图控制器NewLinkViewController中设置一个浮点值

这是我的密码:

    - (IBAction)selectSize:(id)sender {
UIButton *selectSize = (UIButton *) sender;
sizeChosen = [[[selectSize titleLabel] text] floatValue];
[self dismissViewControllerAnimated:YES completion:^{
    [mainController setMySizeLabel:sizeChosen];
    [NewLinkViewController.sizeChosen = sizeChosen];

}];
}

我得到了这个错误:(表示“在'NewLinkViewController'类型的对象上找不到'sizeChosen'属性)

很明显,我的NewLinkViewController中有@property。h如下所示:

    @property float sizeChosen;

我做错了什么?

看起来您在类上设置属性,而不是类的对象
[NewLinkViewController.sizeChosen=sizeChosen]

此外,如果你使用点语法,你不需要方括号。

你可以试试这个

- (IBAction)selectSize:(id)sender {
UIButton *selectSize = (UIButton *) sender;
sizeChosen = [[[selectSize titleLabel] text] floatValue];
[self dismissViewControllerAnimated:YES completion:^{
    [mainController setMySizeLabel:sizeChosen];
    NewLinkViewController *newLinkController = [[NewLinkViewController alloc] init];
    newLinkController.sizeChosen = sizeChosen;

}];

像这样申报你的财产

@property (nonatomic, assign) float sizeChosen;
并设置sizeChosen属性,如下所示

  - (IBAction)selectSize:(id)sender {
      UIButton *selectSize = (UIButton *) sender;
      sizeChosen1 = [[[selectSize titleLabel] text] floatValue];
      [self dismissViewControllerAnimated:YES completion:^{
        [mainController setMySizeLabel:sizeChosen1];
        newLinkViewController.sizeChosen = sizeChosen1;//newLinkViewController should be the instance of NewLinkViewController 

     }];

您需要使用类NewLinkViewController的实例访问float变量属性,正如rounak所建议的,在访问properties方法时不需要使用方括号。 如下所示:-

  NewLinkViewController *newLinkVw=[[NewLinkViewController alloc] initWithNibName:@"yourVwNibnm" bundle:nil];
 //now access your property
   newLinkVw.sizeChosen=sizeChosen;

注意:-请确保在设置或访问类的属性之前。您的类实例应该存在。

您试图在类上设置属性,而您应该在
NewLinkViewController
的实例上设置属性。您可能需要将该实例传递给正在进行“选择”的视图控制器。(除非您确实使用大写字母命名了实例变量,在这种情况下我错了。)请尝试:
@property(nonatomic,assign)CGFloat sizeChosen