无法将文本字段的值传递给iOS中的其他ViewController [英] Can not pass value of textfield to other viewcontroller in ios

查看:40
本文介绍了无法将文本字段的值传递给iOS中的其他ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将LoginView中的文本字段的值传递给uploadview,但是UserLogin1始终为NULL(0x000000)这是我的代码:loginvuew.h

I want to pass value of textfield in LoginView to uploadview but UserLogin1 always is NULL ( 0x000000) This is my codes: loginvuew.h

@property (nonatomic,retain) IBOutlet UITextField *username;

loginview.m

loginview.m

-(IBAction)LoginButton:(id)sender{
 uploadview= [[UploadTab alloc] initWithFrame:CGRectMake(0,0,0,0) andUsertring:username.text];
}

uploadview.h

uploadview.h

@property (nonatomic, copy) NSString *UserLogin1;
- (id)initWithFrame:(CGRect)frame andUsertring:(NSString *)strUser;

uploadview.m

uploadview.m

- (id)initWithFrame:(CGRect)frame andUsertring:(NSString *)strUser
{
    if (self) {
        UserLogin1=[[NSString alloc] init];
        UserLogin1 = strUser;

    }
    return self;
}

- (void)viewDidLoad
{
 NSLog(@"User login: %@",UserLogin1);
        self.navigationItem.title = [NSString stringWithFormat: @"Hello, %@",UserLogin1];

}

在initWithFrame()中运行时,字符串传递正确,但在ViewDidLoad中传递的字符串不正确.并且UserLogin1变量始终为0x00000.你有建议吗?提前感谢

WHen run in initWithFrame(), string passing correct but in ViewDidLoad is not correct. And UserLogin1 variable always is 0x00000. DO you have sugesstions? Thansk in advance

推荐答案

您正在弄乱我认为的事情.UploadTab是什么类?该视图没有方法viewDidload!这是UIViewController的.如果是ViewController,则应使用initWithNibName:bundle或smth进行适当分配.添加:您的代码缺少实际的alloc-init方法

You are messing up things I think. What class is an UploadTab ? The view does not have a method viewDidload ! It's UIViewController's one. If it is ViewController then you should allocate it properly with initWithNibName:bundle or smth like that. ADDED: Your code missing actual alloc-init method

- (id)initWithFrame:(CGRect)frame andUsertring:(NSString *)strUser
{
    // self is nil here! It is in almost every cases done like self = [[super alloc] initBlaBla]
    if (self) {
        UserLogin1=[[NSString alloc] init];
        UserLogin1 = strUser;

    }
    return self;
}

这篇关于无法将文本字段的值传递给iOS中的其他ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆