简体   繁体   English

如何在带有Tab Bar Controller的View Controller之间传输浮点值?

[英]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.

相关问题 使用标签栏时在视图控制器之间传递数据 controller - Passing data between view controllers when using a tab bar controller 在视图控制器和标签栏控制器之间传递数据 - Passing data between view controllers and tab bar controller 选项卡视图控制器之间的数据传输 - swift - Data transfer between tab view controllers - swift 如何在故事板的标签栏上启动导航控制器的第三个视图控制器 - how to start third view controller of navigation controllers on tab bar in storyboard 替换选项卡栏控制器的视图控制器之一 - Replace one of the view controllers of tab bar controller 后续视图控制器上缺少标签栏控制器 - Tab Bar Controller missing on subsequent View Controllers 使用自定义选项卡栏控制器类在两个视图控制器之间传递数据 - Pass Data Between Two View Controllers Using a Custom Tab Bar Controller Class 检查View Controllers的选项卡栏成员是我的View Controller吗? - Checking View Controllers' tab bar member is my view controller? 如何在视图控制器之间的Xcode 8上传输图形? - How to transfer a drawing on Xcode 8 between view controllers? 在视图控制器->标签栏控制器->导航控制器->视图控制器的层次结构内旋转视图控制器 - Rotating view controllers within a hierarchy of View Controller -> Tab Bar Controller -> Navigation Controller -> View Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM