Ios 我无法通过标记目标c更改标签文本

Ios 我无法通过标记目标c更改标签文本,ios,objective-c,Ios,Objective C,我正在使用一个登录的应用程序。我想做的是,登录后,一个标签显示用户名 这是我的密码: #import "ViewController.h" @interface ViewController () @property (strong, nonatomic) IBOutlet UITextField *userNameTextField; @property (strong, nonatomic) IBOutlet UITextField *passwordTextField; @end

我正在使用一个登录的应用程序。我想做的是,登录后,一个标签显示用户名

这是我的密码:

#import "ViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UITextField *userNameTextField;

@property (strong, nonatomic) IBOutlet UITextField *passwordTextField;

@end


@implementation ViewController

- (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)Login:(id)sender {


    if ([_userNameTextField.text isEqualToString:@""] || [_passwordTextField.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Please Fill all the field" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }

    NSString *strURL = [NSString stringWithFormat:@"http://192.168.1.11:8888/swift/login.php?userName=%@&password=%@",_userNameTextField.text, _passwordTextField.text];

    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

    NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

    if ([strResult isEqualToString:@"1"])
    {

        NSString *username = _userNameTextField.text;

        UILabel *myLabel = (UILabel *)[self.view viewWithTag:100];
        myLabel.text = [NSString stringWithFormat:@" Label %@",username];


        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"logedIn"];
        vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:vc animated:YES completion:NULL];



    }

    else if ([strResult isEqualToString:@"0"])
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Wrong username / password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];


        return;
    }

    else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Server Error" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        return;
    }
}

@end
这是我的故事板的图像

在图像中,您可以看到我第一次出现在左下角。第二个屏幕在右上角。两者都有ViewController类


我正在使用xcode 7.0

在.h中为标签设置属性,并将其链接到故事板上

@property (nonatomic, strong) IBOutlet UILabel *label;
然后,在显示新的视图控制器之前,您可以设置该标签的文本

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"logedIn"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
vc.label.text = [NSString stringWithFormat:@" Label %@",username];
[self presentViewController:vc animated:YES completion:NULL];

U有两个不同的
ViewController
实例,这意味着
UITextField
在第一个实例中的更改对第二个实例不可见

你需要有一个对象(我们称之为
模型
),它将保存数据并根据需要进行更改

无论如何,改变你的架构,让它有一个
模型
层来保存你的数据

如果你想让事情在这里具体化,但实际效果不佳,请在
AppDelegate
中创建
NSString
,并在更改时在那里设置数据。并根据需要从那里获取数据

但是再一次,
更改您的体系结构以具有

您应该使用segues,而不是InstanceViewController的标识符:。这就是他们的目的。为什么要将uiview转换为uilabel?你不能像uilabel.tag那样直接访问标签标签吗?你把IBoulet链接到你的故事板了吗?