[英]How to transfer a float value between View Controllers with Tab Bar Controller?
I have 1 original tab, tab A, which contains a button to segue to a second ViewController (B). 我有1个原始选项卡,即选项卡A,其中包含一个按钮,可用于连接到第二个ViewController(B)。 In VC B, a number is selected and changes a label in Tab A to say that number (All of that works perfectly). 在VC B中,选择了一个数字,并在Tab A中更改了一个标签以说出该数字(所有这些都可以正常使用)。
I have a method that makes a new tab, and I need to know how to get the float value from Tab A and VC B to be recognized as the same value in Tab C (the new tab). 我有一个制作新标签的方法,我需要知道如何从标签A和VC B获取浮点值,以便在标签C(新标签)中将其识别为相同的值。 Any help is appreciated! 任何帮助表示赞赏!
Edit: Here is the method I have to make a new tab 编辑:这是我必须制作新标签的方法
-(void)makeNewTab: (NSString *)linkToSnipe {
NSMutableArray* tabs = [[NSMutableArray alloc] init];
[tabs addObjectsFromArray:self.tabBarController.viewControllers];
NewLinkViewController* newVC = [self.storyboard instantiateViewControllerWithIdentifier:@"Link"];
[tabs addObject: newVC];
UITabBarItem* item = [[UITabBarItem alloc] init];
NSString* itemTitle = [NSString stringWithFormat:@"Link # %lu", (unsigned long)[itemsAlreadyAddedToCart count]];
[item setTitle: itemTitle];
[item setImage:[UIImage imageNamed:@"shoe.png"]];
[newVC setTabBarItem:item];
[self.tabBarController setViewControllers: [NSArray arrayWithArray:tabs]];
int indexOfNewTab = [tabs count]-1;
[newVC setLinkToSnipe:linkToSnipe];
[newVC setSizeIWant: sizeChosen];
self.tabBarController.selectedIndex = indexOfNewTab;
} }
setLinkToSnipe:linktosnipe works perfectly, that string is known as the same thing in the new tab. setLinkToSnipe:linktosnipe可以完美地工作,该字符串在新选项卡中被称为同一事物。 setSizeIWant: sizeChosen does not work. setSizeIWant:sizeChosen不起作用。 Size chosen is the float value I need in tab C 选择的大小是我在标签C中需要的浮点值
如果不看代码,除了以与现在在选项卡A和B之间进行操作相同的方式进行操作外,很难提出建议。创建选项卡C时,为其提供一个属性,该属性可以由创建它的任何人来设置。
you have to have a float value in tab C : 您必须在标签C中具有浮点值:
@property (nonatomic) float floatValue;
and change it by adding the following at the end of tab B and tab A: 并通过在标签B和标签A的末尾添加以下内容来进行更改:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"segue"]){
ViewCont *vc = segue.destinationViewController;
vc.floatValue = value;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.