Ios 标签值不变

Ios 标签值不变,ios,objective-c,uilabel,uistoryboardsegue,Ios,Objective C,Uilabel,Uistoryboardsegue,我正在用Objective C编写一个程序,它使用两个不同的视图来输入数据。一个视图仅显示视图(PSACurrentGame),另一个视图输入数据(PSAEnterScores)。我正在使用“prepareforsegue”方法将数据从PSAEnterScores传递到PSACurrentGame。问题是标签没有改变。知道为什么吗 PSACurrentGame.m: #import "PSACurrentGame.h" #import "PSAGlobal.h" @interface PSAC

我正在用Objective C编写一个程序,它使用两个不同的视图来输入数据。一个视图仅显示视图(PSACurrentGame),另一个视图输入数据(PSAEnterScores)。我正在使用“prepareforsegue”方法将数据从PSAEnterScores传递到PSACurrentGame。问题是标签没有改变。知道为什么吗

PSACurrentGame.m:

#import "PSACurrentGame.h"
#import "PSAGlobal.h"

@interface PSACurrentGame ()



@end

@implementation PSACurrentGame

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view
    PSAGlobal *global = [PSAGlobal getInstance];

    self.player1.text = global.player1Name;
    self.player2.text = global.player2Name;
    self.player3.text = global.player3Name;
    self.player4.text = global.player4Name;
    self.player5.text = global.player5Name;
    self.player6.text = global.player6Name;

    if ([self.player3.text isEqual: @""]) {
        self.player3.hidden = YES;
        self.R1P3Phase.hidden = YES;
        self.R1P3Score.hidden=YES;
        self.R2P3Phase.hidden = YES;
        self.R2P3Score.hidden=YES;
        self.R3P3Phase.hidden = YES;
        self.R3P3Score.hidden=YES;
        self.ToP3Phase.hidden = YES;
        self.ToP3Score.hidden=YES;
    }

    if ([self.player4.text isEqual: @""]) {
        self.player4.hidden = YES;
        self.R1P4Phase.hidden = YES;
        self.R1P4Score.hidden=YES;
        self.R2P4Phase.hidden = YES;
        self.R2P4Score.hidden=YES;
        self.R3P4Phase.hidden = YES;
        self.R3P4Score.hidden=YES;
        self.ToP4Phase.hidden = YES;
        self.ToP4Score.hidden=YES;
    }
    if ([self.player5.text isEqual: @""]) {
        self.player5.hidden = YES;
        self.R1P5Phase.hidden = YES;
        self.R1P5Score.hidden=YES;
        self.R2P5Phase.hidden = YES;
        self.R2P5Score.hidden=YES;
        self.R3P5Phase.hidden = YES;
        self.R3P5Score.hidden=YES;
        self.ToP5Phase.hidden = YES;
        self.ToP5Score.hidden=YES;
    }

    if ([self.player6.text isEqual: @""]) {
        self.player6.hidden = YES;
        self.R1P6Phase.hidden = YES;
        self.R1P6Score.hidden=YES;
        self.R2P6Phase.hidden = YES;
        self.R2P6Score.hidden=YES;
        self.R3P6Phase.hidden = YES;
        self.R3P6Score.hidden=YES;
        self.ToP6Phase.hidden = YES;
        self.ToP6Score.hidden=YES;
    }

    if ([self.player4.text isEqual: @""] && [self.player5.text isEqual:@""] && [self.player6.text isEqual:@""]) {
        self.R1List2.hidden = YES;
        self.R2List2.hidden = YES;
        self.R3List2.hidden = YES;
        self.ToList2.hidden = YES;
    }


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
- (void)viewDidLoad
{
[super viewDidLoad];
// set text to your label
 R3P1Score.text=gameName;
}
PSACurrentGame.h:

#import <UIKit/UIKit.h>

@interface PSACurrentGame : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *player1;
@property (strong, nonatomic) IBOutlet UILabel *player2;
@property (strong, nonatomic) IBOutlet UILabel *player3;
@property (strong, nonatomic) IBOutlet UILabel *player4;
@property (strong, nonatomic) IBOutlet UILabel *player5;
@property (strong, nonatomic) IBOutlet UILabel *player6;
@property (strong, nonatomic) IBOutlet UILabel *R1P1Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P1Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P1Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P1Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P1Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P1Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP1Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP1Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1P2Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P2Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P2Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P2Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P2Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P2Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP2Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP2Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1P3Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P3Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P3Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P3Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P3Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P3Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP3Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP3Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1P4Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P4Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P4Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P4Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P4Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P4Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP4Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP4Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1P5Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P5Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P5Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P5Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P5Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P5Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP5Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP5Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1P6Score;
@property (strong, nonatomic) IBOutlet UILabel *R1P6Phase;
@property (strong, nonatomic) IBOutlet UILabel *R2P6Score;
@property (strong, nonatomic) IBOutlet UILabel *R2P6Phase;
@property (strong, nonatomic) IBOutlet UILabel *R3P6Score;
@property (strong, nonatomic) IBOutlet UILabel *R3P6Phase;
@property (strong, nonatomic) IBOutlet UILabel *ToP6Score;
@property (strong, nonatomic) IBOutlet UILabel *ToP6Phase;
@property (strong, nonatomic) IBOutlet UILabel *R1List2;
@property (strong, nonatomic) IBOutlet UILabel *R2List2;
@property (strong, nonatomic) IBOutlet UILabel *R3List2;
@property (strong, nonatomic) IBOutlet UILabel *ToList2;

@end
PSA.h:

#import <UIKit/UIKit.h>

@interface PSAEnterScores : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *player1txt;
@property (weak, nonatomic) IBOutlet UITextField *player2txt;
@property (weak, nonatomic) IBOutlet UITextField *player3txt;
@property (weak, nonatomic) IBOutlet UITextField *player4txt;
@property (weak, nonatomic) IBOutlet UITextField *player5txt;
@property (weak, nonatomic) IBOutlet UITextField *player6txt;
@property (weak, nonatomic) IBOutlet UILabel *player1Name;
@property (weak, nonatomic) IBOutlet UILabel *player2Name;
@property (weak, nonatomic) IBOutlet UILabel *player3Name;
@property (weak, nonatomic) IBOutlet UILabel *player4Name;
@property (weak, nonatomic) IBOutlet UILabel *player5Name;
@property (weak, nonatomic) IBOutlet UILabel *player6Name;

@end
#导入
@接口:UIViewController
@属性(弱、非原子)IBOutlet UITextField*player1txt;
@属性(弱、非原子)IBOutlet UITextField*Player2Text;
@属性(弱、非原子)IBOutlet UITextField*player3txt;
@属性(弱、非原子)IBOutlet UITextField*Player4Text;
@属性(弱、非原子)IBOutlet UITextField*player5txt;
@属性(弱、非原子)IBOutlet UITextField*player6txt;
@属性(弱、非原子)IBUILabel*player1Name;
@属性(弱、非原子)IBUILabel*player2Name;
@属性(弱、非原子)IBUILabel*player3Name;
@属性(弱、非原子)IBUILabel*player4Name;
@属性(弱、非原子)IBUILabel*player5Name;
@属性(弱、非原子)IBUILabel*player6Name;
@结束
一次输入数据后记录:

2013-11-25 19:04:08.810第10阶段评分应用[34601:11303]接口生成器文件中的未知等级PSA。
2013-11-25 19:08:11.607第10阶段评分应用[34601:11303]P1ToScore的值:(空)

(课程名称为第10阶段评分申请)


我不知道它为什么在Interface Builder文件中显示未知类PSA。我没有名为“PSA”的类,它只是我的类的前缀。

prepareForSegue:在
viewDidLoad:
之前调用,因此您的
IBOutlet
将为零。尝试将传入值设置为
NSString
,然后使用该字符串填充
UIlabel
上的
viewDidLoad:

比如说

在游戏中。h: //创建属性 @属性(非原子,强)NSString*gameName

m:修改你的分数

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{

 PSACurrentGame *pass = (PSACurrentGame *)segue.destinationViewController;
 pass.gameName=[NSString alloc]initWithString:pass.R2P1Score.text]
}
在游戏中。m:

#import "PSACurrentGame.h"
#import "PSAGlobal.h"

@interface PSACurrentGame ()



@end

@implementation PSACurrentGame

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view
    PSAGlobal *global = [PSAGlobal getInstance];

    self.player1.text = global.player1Name;
    self.player2.text = global.player2Name;
    self.player3.text = global.player3Name;
    self.player4.text = global.player4Name;
    self.player5.text = global.player5Name;
    self.player6.text = global.player6Name;

    if ([self.player3.text isEqual: @""]) {
        self.player3.hidden = YES;
        self.R1P3Phase.hidden = YES;
        self.R1P3Score.hidden=YES;
        self.R2P3Phase.hidden = YES;
        self.R2P3Score.hidden=YES;
        self.R3P3Phase.hidden = YES;
        self.R3P3Score.hidden=YES;
        self.ToP3Phase.hidden = YES;
        self.ToP3Score.hidden=YES;
    }

    if ([self.player4.text isEqual: @""]) {
        self.player4.hidden = YES;
        self.R1P4Phase.hidden = YES;
        self.R1P4Score.hidden=YES;
        self.R2P4Phase.hidden = YES;
        self.R2P4Score.hidden=YES;
        self.R3P4Phase.hidden = YES;
        self.R3P4Score.hidden=YES;
        self.ToP4Phase.hidden = YES;
        self.ToP4Score.hidden=YES;
    }
    if ([self.player5.text isEqual: @""]) {
        self.player5.hidden = YES;
        self.R1P5Phase.hidden = YES;
        self.R1P5Score.hidden=YES;
        self.R2P5Phase.hidden = YES;
        self.R2P5Score.hidden=YES;
        self.R3P5Phase.hidden = YES;
        self.R3P5Score.hidden=YES;
        self.ToP5Phase.hidden = YES;
        self.ToP5Score.hidden=YES;
    }

    if ([self.player6.text isEqual: @""]) {
        self.player6.hidden = YES;
        self.R1P6Phase.hidden = YES;
        self.R1P6Score.hidden=YES;
        self.R2P6Phase.hidden = YES;
        self.R2P6Score.hidden=YES;
        self.R3P6Phase.hidden = YES;
        self.R3P6Score.hidden=YES;
        self.ToP6Phase.hidden = YES;
        self.ToP6Score.hidden=YES;
    }

    if ([self.player4.text isEqual: @""] && [self.player5.text isEqual:@""] && [self.player6.text isEqual:@""]) {
        self.R1List2.hidden = YES;
        self.R2List2.hidden = YES;
        self.R3List2.hidden = YES;
        self.ToList2.hidden = YES;
    }


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
- (void)viewDidLoad
{
[super viewDidLoad];
// set text to your label
 R3P1Score.text=gameName;
}

抱歉,我应该如何解决在viewDidLoad之前调用prepareForSegue的问题?我有点困惑。谢谢你!成功了!最后,我一直在寻找这个问题的答案。这是我在这个问题上问的第二个问题(我之前的一个问题解决了问题的另一个方面)!