gpt4 book ai didi

iOS:在 View 之间传递数据(数组值或字符串)?

转载 作者:行者123 更新时间:2023-12-01 18:30:01 25 4
gpt4 key购买 nike

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

-(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;
...

关于iOS:在 View 之间传递数据(数组值或字符串)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com