我想将LoginView中的textfield值传递给uploadview,但UserLogin1总是为NULL(0x000000) 这是我的代码: loginvuew.h
@property (nonatomic,retain) IBOutlet UITextField *username;
loginview.m
-(IBAction)LoginButton:(id)sender{
uploadview= [[UploadTab alloc] initWithFrame:CGRectMake(0,0,0,0) andUsertring:username.text];
}
uploadview.h
@property (nonatomic, copy) NSString *UserLogin1;
- (id)initWithFrame:(CGRect)frame andUsertring:(NSString *)strUser;
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。你有sugesstions? Thansk提前
答案 0 :(得分:0)
你搞砸了我想的事情。什么类是UploadTab?视图没有方法viewDidload!这是UIViewController的一个。如果它是ViewController,那么你应该使用initWithNibName正确分配它:bundle或smth就是这样。 添加: 您的代码缺少实际的alloc-init方法
- (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;
}