一个页面(ViewController)随便写控件,button ,View之类的   addsubview  添加到 self.VIEW 上。   结果控件完全不显示。
但是通过  [[UIApplication sharedApplication].keyWindow addSubview:btn]  却可以显示出来。。
控件 frame 正常    且打印 subviews 可以看到 控件 添加到 view 上了。   
搞不懂到底什么原因。
使用  bringSubviewToFront  依然不显示。所以感觉也不是顺序的原因。
求助大神帮忙。

解决方案 »

  1.   

    viewcontroller本身有没有显示呢,是不是没有设置 self.window.rootviewcontroller = viewcontroller?
      

  2.   


    bringSubviewToFront: 
    把指定的子视图移动到顶层 
    - (void)bringSubviewToFront:(UIView *)view 
    参数 
    view 
    需要移到顶层的视图 
      

  3.   

    视图本身当然是显示的。 也没有特殊设置。- (void)viewDidLoad {
        @try {
            [super viewDidLoad];
            if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)){
                self.edgesForExtendedLayout = UIRectEdgeNone;
                self.extendedLayoutIncludesOpaqueBars = NO;
                self.modalPresentationCapturesStatusBarAppearance = NO;
            }
            
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 100, 200, 100)];
            view.backgroundColor = [UIColor purpleColor];
            [self.view addSubview:view];
            //[[UIApplication sharedApplication].keyWindow addSubview:view];
            
            NavigationRoot *navRoot = (id)self.navigationController;
            [navRoot drawNavBar:self.navigationItem title:@"选择客户"];
            rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
            rightButton.frame = CGRectMake(0, 0, 40, 30);
            [rightButton setTitle:@"下载" forState:UIControlStateNormal];
            [rightButton addTarget:self action:@selector(pressRightBtn:) forControlEvents:UIControlEventTouchUpInside];
            UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
            self.navigationItem.rightBarButtonItem = rightButtonItem;
            
            [self.tableview registerNib:[UINib nibWithNibName:@"CustomerTableViewCell2" bundle:nil]  forCellReuseIdentifier:@"CustomerTableViewCell2"];
            isPlanned = 0;
            
            [[Common Init] clipTableViewMoreLines:_tableview];
            
            [self getAllTableViewDataSources];
            
            [self showLocationMessage];
            
            [self initBottomSearchView];        [self initSearchView];    }
        @catch (NSException *exception) {
            [CommonErrorHandler Handler:exception];
        }
    }如上  视图生命周期方法中只实现了 ViewDidLoad   我将其他代码全部注释掉。只留下测试 View  依然不显示。但是加在 keywindow 可以显示。
      

  4.   


    没用的。早试过了。我怀疑是 xib 的问题  但是又调不出来。因为我把所有代码注释掉,只留下测试 View   依然不显示。
      

  5.   

    你只写个简单  的  add subview  的方法测试看看。
      

  6.   

    @try 删掉试试呢?
      

  7.   

      self.window.rootviewcontroller = viewcontroller;
       [self.window makeKeyAndVisible];
      

  8.   

    @try @catch是用来捕捉异常的
      

  9.   

    我碰到的问题跟你的完全一样,后来我发现UIView *buttomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tableView.frame), SCREEN_WIDTH, buttomHeight)];     这样获取上面视图的位置再设置这个视图的位置就好了