1

如何使用以下代码将 NSString 值传递给“webwhatsnew”子视图。谢谢

-(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];
}
4

3 回答 3

2

在 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;
...
于 2012-04-13T07:31:07.553 回答
2

您需要在WebWhatsnewView. 这样您就可以设置为

webwhatsnew.<your_string_entity> = myString;

一定要合成它。

于 2012-04-13T07:34:41.893 回答
0

还有另一种方法可以使用方法。只需在 WebWhatsnewView 类中声明和定义参数类型方法。

在.h

-(void)setSomeData:(NSString*)str;

-(void)setSomeData:(NSString*)str
{
  NSString *myString=str;
}

然后调用它

-(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"];
}
于 2012-04-13T07:48:43.397 回答