我试图让我的第一个 View Controller 中的 UITextField 电子邮件成为我下一个 View Controller 中的 UILabel。它说有一个错误,指出 NSString 没有可见的@interface 声明选择器初始值。当您将接口(interface)导入 vc2 时,我认为接口(interface)是从 vc1.h 文件加载的?你能帮忙的话,我会很高兴。继承人我到目前为止:
vc1.h
#import <UIKit/UIKit.h>
@interface loginUserViewController : UIViewController
@property (nonatomic, retain, strong) IBOutlet UITextField *email;
@property (nonatomic, retain) IBOutlet UITextField *password;
@property (nonatomic, retain) IBOutlet UIButton *login;
@property (nonatomic,retain) IBOutlet UIButton *registerBtn;
-(IBAction)loginUser:(id)sender;
@end
vc2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
@interface Home : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *username;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *Nav;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *logout;
-(IBAction)logout:(id)sender;
-(IBAction)bandHome:(id)sender;
@end
vc2.m
import "Home.h"
#import "loginUserViewController.h"
@interface Home ()
@end
@implementation Home
@synthesize username, band1, band2, band3;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
loginUserViewController *object = [[loginUserViewController alloc]init];
NSString *string = [[NSString alloc] initWithFormat:@"%i",[object.email.text initValue]];
username.text = string;
}
vc1.m
#import "loginUserViewController.h"
#import "Home.h"
#import "createBandViewController.h"
@interface loginUserViewController ()
@end
@implementation loginUserViewController
@synthesize email, password;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidload
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setEmail:nil];
[self setPassword:nil];
[super viewDidUnload];
}
-(IBAction)loginUser:(id)sender {
if ([email.text isEqualToString:@""] || [password.text isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Please Fill all the field" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
最佳答案
简单地替换这个字符串:
NSString *string = [[NSString alloc] initWithFormat:@"%i",[object.email.text initValue]];
用这个字符串:
NSString *string = [[NSString alloc] initWithFormat:@"%i",[object.email.text intValue]];
如果您只想将电子邮件作为字符串,则将其替换为该字符串
NSString *string = [[NSString alloc] initWithFormat:@"%@",object.email.text];
您的错误将得到解决。希望对您有所帮助:)
关于ios - Objective-C 使 vc1 的 UITextField 成为 UILabel vc2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35644577/