子视图没有响应水龙头/触摸;

时间:2014-07-25 05:13:33

标签: ios uitabbar

我创建了一个TabbBar,并使用以下内容获取另一个ViewController,如下面的子视图。我正在成功加载视图,但我无法与视图中加载的Viewcontroller.view进行交互。

可以看到完整的.m和.h文件代码here

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
[_InnerContentView removeFromSuperview];
_InnerContentView = nil;
_InnerContentView=[[UIView alloc]init];//UIView Inside the Main View;Used to add otherViews as sub Views
 vc=nil;//UIViewController;

switch (item.tag)
{
    case 10:

        vc=[[IndProjectViewController alloc]initWithNibName:@"IndProjectViewController" bundle:nil];
        self.navigationItem.title = @"Project";
        vc.view.frame=CGRectMake(0, 0,_InnerContentView.frame.size.width,_InnerContentView.frame.size.height-self.tabBar.frame.size.height);

       [_InnerContentView addSubview:vc.view];
       [self.view addSubview:_InnerContentView];
        break;

    case 11:
        vc=[[IndTasksViewController alloc]initWithNibName:@"IndTasksViewController" bundle:nil];
        self.navigationItem.title = @"Task";
        vc.view.frame=CGRectMake(0, 0,_InnerContentView.frame.size.width,_InnerContentView.frame.size.height-self.tabBar.frame.size.height);
        [_InnerContentView addSubview:vc.view];
        [self.view addSubview:_InnerContentView];
        break;
    case 12:
        vc=[[IndDocumentsViewController alloc]initWithNibName:@"IndDocumentsViewController" bundle:nil];
        self.navigationItem.title = @"Documents";
        vc.view.frame=CGRectMake(0, 0,_InnerContentView.frame.size.width,_InnerContentView.frame.size.height-self.tabBar.frame.size.height);

        [_InnerContentView addSubview:vc.view];
        [self.view addSubview:_InnerContentView];

        break;

}}

这有什么不妥。

可以看到完整的.m和.h文件代码here

1 个答案:

答案 0 :(得分:0)

在UItabbar delgate方法中添加以下内容将解决问题,请检查以下内容,因为这是我经常遇到的一个愚蠢的错误。

    _InnerContentView.frame=CGRectMake(x, y,self.view.frame.size.width,self.view.frame.size.height-self.tabBar.frame.size.height-y);
添加后

将如下所示:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
 [_InnerContentView removeFromSuperview];
_InnerContentView = nil;
_InnerContentView=[[UIView alloc]init];
_InnerContentView.frame=CGRectMake(x, y,self.view.frame.size.width,self.view.frame.size.height-self.tabBar.frame.size.height-y);
  vc=nil;
switch (item.tag)
{
    case 10:
        self.navigationItem.title = @"Project";
        vc=[[IndProjectViewController alloc]initWithNibName:@"IndProjectViewController" bundle:nil];
        vc.view.frame=CGRectMake(0, 0, _InnerContentView.frame.size.width,_InnerContentView.frame.size.height-self.tabBar.frame.size.height);
        [_InnerContentView addSubview:vc.view];
        [self.view addSubview:_InnerContentView];