gpt4 book ai didi

iphone - 无法使标签接收字符串

转载 作者:行者123 更新时间:2023-11-29 04:12:11 25 4
gpt4 key购买 nike

编辑:

我在一个 View 中有一个文本字段、一个按钮和一个标签,在另一个 View 上有一个标签,它们由不同 View Controller 控制,在我的代码中我采用文本字段的浮点值,将其转换为字符串,然后我将这个字符串放入两个标签中。但问题是,只有带有文本字段和按钮的 View 上的标签会收到它,另一个标签(位于另一个 View 上)不会收到任何内容!

第一个.h

    #import <UIKit/UIKit.h>

@interface NotasFirstViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *tfield;
- (IBAction)calcular:(id)sender;
-(IBAction)clicarFora:(id)sender;
-(IBAction)tirarteclado:(id)sender;
@property (strong, nonatomic) NSString *valorstr;
@property (strong, nonatomic) IBOutlet UILabel *mostradordeteste;
@end

第一个.m

#import "NotasFirstViewController.h"
#import "NotasSecondViewController.h"

@interface NotasFirstViewController ()

@end

@implementation NotasFirstViewController
@synthesize valorstr;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


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

- (IBAction)calcular:(id)sender {

float valor = [_tfield.text floatValue];
NSString *valorstr = [[NSString alloc] initWithFormat:@"%.2f", valor];
NSLog(@"%.2f", valor);
NSLog(valorstr);
_mostradordeteste.text = valorstr;
NotasSecondViewController *second = [[NotasSecondViewController alloc] init];

}

-(IBAction)clicarFora:(id)sender{

[_tfield resignFirstResponder];

}
-(IBAction)tirarteclado:(id)sender{

[sender resignFirstResponder];

}


@end

第二个.h

#import <UIKit/UIKit.h>

@interface NotasSecondViewController : UIViewController{

NSString *valorclasstwo;
IBOutlet UILabel *classe2labelvalor;

}

@end

第二.m

#import "NotasSecondViewController.h"
#import "NotasFirstViewController.h"

@interface NotasSecondViewController ()

@end

@implementation NotasSecondViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

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

NotasFirstViewController *n1 = [[NotasFirstViewController alloc] init];
valorclasstwo = [n1 valorstr];
classe2labelvalor.text = valorclasstwo;
}

@end

conectionsfirst

conectionssecond

最佳答案

查看两个标签的输出是否正确连接(黑色圆圈)。如果圆圈未填充,则表示有问题。

关于iphone - 无法使标签接收字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14249766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com