使用tabBar在视图之间传递数据

时间:2012-05-18 15:38:25

标签: ios xcode uiviewcontroller expression uitabbar

好的,所以我的应用程序的一部分,我正在努力在视图之间传递浮点变量,一切都很好,但所有按钮看起来有点乱。为了让我快完成,我想知道是否可以在现有视图中添加tabBar并清理它。我找到了一个很好的教程,并得到它链接并报告我在NSLog中选择的选项卡,所以继续并粘贴我曾经用于相同功能的按钮的代码。一切都有点搞笑,我不得不做一些新的变量,我要归结为我无法弄清楚的最后一个错误。  我第一次调用patternRafter

时正在调用一个预期的表达式
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %d", item.tag);

[self activateTab:item.tag];
}

- (void)activateTab:(int)index {
switch (index) {
    case 1:

        patternRafter *patternRafter1 = [[patternRafter  alloc]initWithNibName:nil bundle:nil];

        BuildNavAppDelegate *buildNavDelegate = (BuildNavAppDelegate *)[[UIApplication sharedApplication]delegate];

        buildNavDelegate.TLPMR = [TLMR text];
        buildNavDelegate.comRaftBirdPassed = [comBird text];
        buildNavDelegate.comRaftLengthPassed = [comRafter text];
        buildNavDelegate.raftThicknessPassed = [rafterWidth text];



        [self presentModalViewController:patternRafter1 animated:YES]; 
        break;
    /*case 2:

        buildersSquare *square1 = [[buildersSquare alloc]initWithNibName:nil bundle:nil];

        BuildNavAppDelegate *buildNavDelegate = (BuildNavAppDelegate *)[[UIApplication sharedApplication]delegate];

        buildNavDelegate.TLPMR = [TLMR text];
        buildNavDelegate.comRaftBirdPassed = [comBird text];
        buildNavDelegate.comRaftLengthPassed = [comRafter text];
        buildNavDelegate.raftThicknessPassed = [rafterWidth text];



        [self presentModalViewController:square1 animated:YES];         
        break;
    case 3:

        self.tab2ViewController =[[tab2 alloc] initWithNibName:@"tab2" bundle:nil];
        [self.view insertSubview:tab2ViewController.view belowSubview:tabbar1];
        if (currentViewController != nil)
            [currentViewController.view removeFromSuperview];
        currentViewController = tab2ViewController;         
        break;*/
    default:
        break;
}

}

任何帮助将不胜感激。谢谢 我刚刚意识到我无法发布图片,因为我还是一个新用户。所以这里有一个链接,如果有人想要检查出来。 http://dl.dropbox.com/u/72193343/Screen%20shot%202012-05-18%20at%209.22.48%20AM.png

2 个答案:

答案 0 :(得分:0)

我认为patternRafter是一个名为PatternRafter的类的实例?如果是这样,该行必须如下所示:

PatternRafter *patternRafter1 = [[PatternRafter alloc] initWithNibName:nil bundle:nil];

Obj-C区分大小写,命名约定要求ivars以小写字母开头,以及以大写字母开头的类。

答案 1 :(得分:0)

- (void)activateTab:(int)index {
switch (index) {
case 1://igot it to work by opening brackets here{

    patternRafter *patternRafter1 = [[patternRafter  alloc]initWithNibName:nil bundle:nil];

    BuildNavAppDelegate *buildNavDelegate = (BuildNavAppDelegate *)[[UIApplication sharedApplication]delegate];

    buildNavDelegate.TLPMR = [TLMR text];
    buildNavDelegate.comRaftBirdPassed = [comBird text];
    buildNavDelegate.comRaftLengthPassed = [comRafter text];
    buildNavDelegate.raftThicknessPassed = [rafterWidth text];



    [self presentModalViewController:patternRafter1 animated:YES]; //local declaration of 'patternRafter1' hides instance variable
    break;//and closing here} 
case 2:

它工作正常,但我收到警告 - 'patternRafter1'的本地声明隐藏了实例变量