0

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

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

登录视图.m

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

上传视图.h

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

上传视图.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。你有什么建议吗?提前谢谢

4

1 回答 1

0

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;
}
于 2013-07-15T08:35:23.243 回答