欢迎来到 IT实训基地-南通科迅教育
咨询电话:0513-81107100
iOS导航控制器和标签控制器互相切换
2017/4/5
南通科迅教育
336
南通IT培训机构怎么选

我的app应用登录后,先是在一个navigation控制器里添加tabelview,需要点击cell,跳转到tabBar控制器,在tabbar里点击navigation的leftBarButtonItem,又会把先前的tableview push出来,再点击cell,又需要跳转到tabBar,如此反复。

先前因为在这个跳转过程中,没有把流程屡清楚,导致这两个东西在频繁切换后会多次重复创建,消耗很多资源。最后闪退。

后来想做成单例,处理不好,又做成懒加载,懒加载属性弄不好,又弄成应用代理的属性懒加载,还是不行。

后来换个思路:因为我的tableview在tabbar里是通过push它的父控制器导航控制器的,所以就用个全局bool变量记录cell点击次数,第一次点击cell,切换根控制器到tabbar,以后再点击cell就调用父控制器的pop,弹回来。压栈--》出栈。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   /* + (instancetype)shareManager {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _shareInstanse = [[HMHTTPManager alloc] init];
        });
        return _shareInstanse;
    }*/
  /*  static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
     AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
     
    [UIApplication sharedApplication].keyWindow.rootViewController=[appDelegate manager];
    });*/
    self.longPressRow = indexPath.row;
    HighFrequencyList *item=[allNews objectAtIndex:self.longPressRow];
    currentName = item.names;
    currentIPAddress=item.ips;
    currentPort = item.portNumber;
    currentdeviceID=item.deviceID;
   
    if(firstTapOrNot == YES) {
        RunState1ViewController *runState=[[RunState1ViewController alloc]init];
        UINavigationController *nav1=[[XMGNavigationController alloc]initWithRootViewController:runState];
        nav1.tabBarItem.title=@"运行";
        nav1.tabBarItem.image=[UIImage imageNamed:@"运行图标"];
        nav1.tabBarItem.selectedImage=[UIImage imageNamed:@"运行图标--点击时态"];
        // nav1.tabBarItem.badgeValue=@"32";
        settingViewController *setting=[[settingViewController alloc]init];
        UINavigationController *nav2=[[XMGNavigationController alloc]initWithRootViewController:setting];
        nav2.tabBarItem.title=@"参数";
        nav2.tabBarItem.image=[UIImage imageNamed:@"338280223"];
        nav2.tabBarItem.selectedImage=[UIImage imageNamed:@"参数-点击时态"];
         
        GMLRunStopViewController *runStop=[[GMLRunStopViewController alloc]init];
        UINavigationController *nav3=[[XMGNavigationController alloc]initWithRootViewController:runStop];
         
        nav3.tabBarItem.title=@"启停";
        nav3.tabBarItem.image=[UIImage imageNamed:@"启停-常态"];
        nav3.tabBarItem.selectedImage=[UIImage imageNamed:@"启停--点击时态"];
         
        warningViewController *warning=[[warningViewController alloc]init];
        UINavigationController *nav4=[[XMGNavigationController alloc]initWithRootViewController:warning];
        nav4.tabBarItem.title=@"告警";
        nav4.tabBarItem.image=[UIImage imageNamed:@"告警-常态"];
        nav4.tabBarItem.selectedImage=[UIImage imageNamed:@"告警点击时态"];
        XMGTabBarController *tabBar=[[XMGTabBarController alloc]init];
        [tabBar addChildViewController:nav1];
        [tabBar addChildViewController:nav2];
        [tabBar addChildViewController:nav3];
        [tabBar addChildViewController:nav4];
     
        [UIApplication sharedApplication].keyWindow.rootViewController=tabBar;
        firstTapOrNot = NO;
  
    }else{
        [self.navigationController popViewControllerAnimated:YES];
 
    }
     
     
//[appDelegate manager];//self.manager;//;
   //tabBarVc.delegate = (id<uitabbarcontrollerdelegate>)[UIApplication sharedApplication].delegate;
/*    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
    NSString *fileName = [path stringByAppendingPathComponent:@"connectConfigure.plist"];
    NSArray *result=[NSArray arrayWithContentsOfFile:fileName];
    IPAddress = result[0];if(IPAddress == nil) IPAddress=@"192.168.3.153";
    name = result[1];if(name == nil) name=@"1A1";
    port= result[2];if(port ==nil) port=@"502";
    deviceID = result[3];if(deviceID == nil) deviceID=@"1";
    */
 
   // GMLIPAddress = result[0];
 //NSLog(@"%@--%@--%d--%d",currentIPAddress,currentName,currentPort,currentdeviceID);
   // NSLog(@"%d",self.longPressRow);
  /*
    NSArray *mingzi=[NSArray arrayWithObjects:@"2A11",@"2A12",@"2A13",
                      @"2A21",@"2A22",@"2A23",
                      @"2B11",@"2B12",@"2B13",
                      @"2B21",@"2B22",@"2B23",nil];
    NSArray *IPdizhi = [NSArray arrayWithObjects:@"192.168.0.11",@"192.168.0.12",@"192.168.0.13",
                        @"192.168.0.21",@"192.168.0.22",@"192.168.0.23",
                        @"192.168.0.31",@"192.168.0.32",@"192.168.0.33",
                        @"192.168.0.41",@"192.168.0.42",@"192.168.0.43", nil];
    if (indexPath.row <= 11 ) {
        IPAddress = IPdizhi[indexPath.row];
        name = mingzi[indexPath.row];
        port= @"502";
        deviceID = @"1";
        
    }*/
    /*
    NSLog(@"当前ip地址是%@",IPAddress);
    NSLog(@"当前端口号是%@",port);
    NSLog(@"当前设备号是%@",deviceID);
    NSLog(@"当前名字是%@",name);
    */
    //tabBar.delegate = (id<uitabbarcontrollerdelegate>)[UIApplication sharedApplication].delegate;
   /* UIStoryboard *storyboard = [UIStoryboard storyboardWithName:NSStringFromClass([RunState1ViewController class]) bundle:nil];
    // 加载箭头指向控制器
    RunState1ViewController *meVc =[storyboard instantiateViewControllerWithIdentifier:@"runState1"];
    [self presentViewController:meVc animated:NO completion:nil];*/
}</uitabbarcontrollerdelegate></uitabbarcontrollerdelegate>

还有,要把一个东西弄成懒加载,需要把这个东西弄成这个类的属性,写一个get方法,如果没有就创建,创建好了赋给属性,如果有就直接返回。

我看别人写的大多是视图做成懒加载,创建出来后,多半要[xxx addSubview:yyy];我以为控制器也需要这样弄,发现不知道add到哪个上面,弄错了,程序崩溃,说找不到父视图,控制器实际上根本不用。

77
关闭
先学习,后交费申请表
每期5位名额
在线咨询
免费电话
QQ联系
先学习,后交费
TOP
您好,您想咨询哪门课程呢?
关于我们
机构简介
官方资讯
地理位置
联系我们
0513-91107100
周一至周六     8:30-21:00
微信扫我送教程
手机端访问
南通科迅教育信息咨询有限公司     苏ICP备15009282号     联系地址:江苏省南通市人民中路23-6号新亚大厦三楼             法律顾问:江苏瑞慈律师事务所     Copyright 2008-