ios - Objective-C 使 vc1 的 UITextField 成为 UILabel vc2

标签 ios objective-c iphone

我试图让我的第一个 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/

相关文章:

objective-c - Cocoa App 启动闪屏

iphone - iOS 7 上的 UILabel 自动调整大小错误

ios - 使用 NSFetchedResultsController 理解 transient 属性

ios - Xcode 10 签名错误 : Frameworks/libswiftsimd. dylib:代码对象根本未签名

objective-c - 有人可以向我解释 Objective-C 方法中类型括号的原因吗?

iphone - 如何在 iOS 应用程序上只运行一次代码(甚至应用程序将被删除并重新安装)?

iphone - 有在线 .plist 编辑器吗?

objective-c - Objective C 的动态 getter 和 setter

ios - fatal error :使用JSON文件和SwiftyJSON解开可选值时意外发现nil

objective-c - 执行异步 URL 请求后的 EXC_BAD_ACCESS