iOS:在视图之间传递数据(数组值或字符串)?
如何使用下面的代码将NSString值传递给“webwhatsnew”子视图。谢谢iOS:在视图之间传递数据(数组值或字符串)?,ios,Ios,如何使用下面的代码将NSString值传递给“webwhatsnew”子视图。谢谢 -(IBAction)Whatsnew { NSString *myString =[URL absoluteString]; // how can I pass this value to "webwhatsnew" subview webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil
-(IBAction)Whatsnew {
NSString *myString =[URL absoluteString];
// how can I pass this value to "webwhatsnew" subview
webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil];
[self.view addSubview:webwhatsnew.view];
}
在WebWhatsnewView中创建NSString属性。然后给它设置一个值。例如:
//WebWhatsnewView.h
...
@property (nonatomic, retain) NSString *someString;
...
-(IBAction)Whatsnew {
NSString *myString =[URL absoluteString];
webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil];
webwhatsnew.someString = myString; //if myString is a string that you want to pass
[self.view addSubview:webwhatsnew.view];
}
希望能有帮助
编辑
//WebWhatsnewView.m
...
@synthesize someString;
...
在WebWhatsnewView中创建NSString属性。然后给它设置一个值。例如:
//WebWhatsnewView.h
...
@property (nonatomic, retain) NSString *someString;
...
-(IBAction)Whatsnew {
NSString *myString =[URL absoluteString];
webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil];
webwhatsnew.someString = myString; //if myString is a string that you want to pass
[self.view addSubview:webwhatsnew.view];
}
希望能有帮助
编辑
//WebWhatsnewView.m
...
@synthesize someString;
...
您需要在
WebWhatsnewView
中有一个字符串属性/实体。这样您就可以设置为
webwhatsnew.<your_string_entity> = myString;
webwhatsnew.=myString;
一定要合成它。您需要在
WebWhatsnewView
中有一个字符串属性/实体。这样您就可以设置为
webwhatsnew.<your_string_entity> = myString;
webwhatsnew.=myString;
一定要合成它。你可以用另一种方法来处理它。只需在WebWhatsnewView类中声明和定义参数类型方法 in.h 英寸 然后叫它进来
-(IBAction)Whatsnew {
NSString *myString =[URL absoluteString];
webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil];
[self.view addSubview:webwhatsnew.view];
[webwhatsnew setSomeData:myString];
//or [webwhatsnew setSomeData:@"Here is the real Strings"];
}
还有另一种方法可以处理方法。只需在WebWhatsnewView类中声明和定义参数类型方法 in.h 英寸 然后叫它进来
-(IBAction)Whatsnew {
NSString *myString =[URL absoluteString];
webwhatsnew = [[WebWhatsnewView alloc]initWithNibName:@"WebWhatsnewView"bundle:nil];
[self.view addSubview:webwhatsnew.view];
[webwhatsnew setSomeData:myString];
//or [webwhatsnew setSomeData:@"Here is the real Strings"];
}
谢谢Novarg。不希望上面的代码不起作用。。请验证我的屏幕截图。@JoshyJoseph你也在.m文件中合成了它吗?我已经添加了@synthesis someString;在WebWhatsnewView.m中,但同样的问题@JoshyJoseph请制作一个屏幕截图(或者最好只是复制粘贴代码)关于WebWhatsnewView.h和WebWhatsnewView.ms,直到同一个问题,请帮助meThanks Novarg。不希望上述代码不起作用。。请验证我的屏幕截图。@JoshyJoseph您是否也在.m文件中合成了它?我已经添加了@synthesis someString;在WebWhatsnewView.m中,但同样的问题@JoshyJoseph,请对WebWhatsnewView.h和WebWhatsnewView.ms进行截图(最好是复制粘贴代码),直到同样的问题,请帮助我