我正在使用登录进行应用程序开发。我想要做的是在登录后标签显示用户名。我无法通过标记目标来更改标签文本c
这里是我的代码:
#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
你应该使用塞格斯而非instantiateViewControllerWithIdentifier :.这是他们的目的。 –
你为什么要将uiview转换为uilabel?不能像uilabel.tag一样直接访问标签标签吗? –