所以我有两个视图控制器,当我从第一个视图控制器currentScore移到JPViewController时,我试图将一个名为LeaderboardViewController的int变量传递给新的视图控制器。

使用下面的代码,我可以在视图控制器之间成功移动,但是似乎无法正确传递数据。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        LeaderboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"lbvc"];
        LeaderboardViewController.scoreToBeAdded = currentScore;
        [self presentViewController:viewController animated:YES completion:nil];


上面的第三行:LeaderboardViewController.scoreToBeAdded = currentScore;给我错误Property 'scoreToBeAdded' not found on object of type 'LeaderboardViewController'

但是,在我的LeaderboardViewController.h文件中,我已经对* scoreToBeAdded进行了引用,因此我不确定为什么无法在其中找到该属性。

#import <UIKit/UIKit.h>

@interface LeaderboardViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property int *scoreToBeAdded;

@end


我想这是我需要解决的第一个问题,但是为了澄清我在做什么,我也在下面的实现文件中也包含了我打算对变量进行的处理。

首先十分感谢!

// LeaderboardViewController.m

- (void)viewDidLoad
    {
        [super viewDidLoad];

        NSLog(@"Leaderboard view loaded w new score to add: %i", _scoreToBeAdded);
    }

最佳答案

LeaderboardViewController.scoreToBeAdded = currentScore;


应该

viewController.scoreToBeAdded = currentScore;




@property int *scoreToBeAdded;


应该

@property (nonatomic, assign) int scoreToBeAdded;

关于ios - 将int变量传递到新的 View Controller 中(以代码形式)- objective-c -Xcode,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29469014/

10-12 00:16
查看更多