0

タグ 1がありUITableViewます。このテーブルを削除して、再びタグ 2 を使用して新しいテーブルを作成すると、シミュレーターでハングアップし、アクションは発生しません。同じタグ1で作成すると、大丈夫です.どんな体でも助けてくれますか?

私のコードは以下です。

- (IBAction)menuTapped:(id)sender {

    UIButton *btn = (UIButton *)sender;

    if (btn.tag==0)
    {
        UIView *subview;
        while ((subview= [[mainView subviews]lastObject])!=nil)

        if ([subview isKindOfClass:[UIView class]]){    
            [subview removeFromSuperview];
        }

        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320,45)];
        [mainView addSubview:view];
        [view setBackgroundColor:[UIColor darkGrayColor]];

        _btnNavigation=[UIButton buttonWithType:UIButtonTypeCustom];
        _btnNavigation.frame=CGRectMake(10, 9, 30, 25);
        [_btnNavigation setImage:[UIImage imageNamed:@"reveal-icon@2x.png"] forState:UIControlStateNormal];
        [_btnNavigation addTarget:self action:@selector(menuTapped:) forControlEvents:UIControlEventTouchUpInside];
        _btnNavigation.tag=0;

        [view addSubview:_btnNavigation];

        UILabel *lblheading=[[UILabel alloc]initWithFrame:CGRectMake(58, 6, 205,32)];
        [view addSubview:lblheading];
        lblheading.text=@"MY TEAMS";
        lblheading.backgroundColor=[UIColor clearColor];
        lblheading.textColor=[UIColor whiteColor];
        lblheading.textAlignment=NSTextAlignmentCenter;
        lblheading.font=[UIFont fontWithName:@"LeagueGothic-Regular" size:32.0];

        searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 45, 320, 44)];
        [mainView addSubview:searchBar];
        searchBar.delegate=self;

        _tableTeams=[[UITableView alloc]initWithFrame:CGRectMake(0,90, 320, 326)];
        [mainView addSubview:_tableTeams];
        _tableTeams.delegate=self;
        _tableTeams.dataSource=self;
        _tableTeams.tag=1;


         AdWhirlView *adWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
         adWhirlView.frame=CGRectMake(0, 430, 320, 50);
         [mainView addSubview:adWhirlView];



        CGRect frame = self->mainView.frame;
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
        [UIView beginAnimations:@"slideMenu" context:( void *)(self->mainView)];
        mainView.hidden=NO;
        if(menuOpen) {

            frame.origin.x = 160;
            menuOpen =NO;

        }
        else
        {
            frame.origin.x = 0;
            menuOpen = YES;
        }

        self->mainView.frame = frame;
        [UIView commitAnimations];

    }
    else if (btn.tag==1)
    {

        UIView *subview;
        while ((subview= [[mainView subviews]lastObject])!=nil)

            if ([subview isKindOfClass:[UIView class]]){

                [subview removeFromSuperview];

            }

        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320,45)];
        [mainView addSubview:view];
        [view setBackgroundColor:[UIColor darkGrayColor]];

        _btnNavigation=[UIButton buttonWithType:UIButtonTypeCustom];
        _btnNavigation.frame=CGRectMake(10, 9, 30, 25);
        [_btnNavigation setImage:[UIImage imageNamed:@"reveal-icon@2x.png"] forState:UIControlStateNormal];
        [_btnNavigation addTarget:self action:@selector(menuTapped:) forControlEvents:UIControlEventTouchUpInside];
        _btnNavigation.tag=1;

        [view addSubview:_btnNavigation];


        UILabel *lblheading=[[UILabel alloc]initWithFrame:CGRectMake(58, 6, 205,32)];
        [view addSubview:lblheading];
        lblheading.text=@"PRICE HILL ATHLETICS";
        lblheading.backgroundColor=[UIColor clearColor];
        lblheading.textColor=[UIColor whiteColor];
        lblheading.textAlignment=NSTextAlignmentCenter;
        lblheading.font=[UIFont fontWithName:@"LeagueGothic-Regular" size:32.0];


        _tableTeams=[[UITableView alloc]initWithFrame:CGRectMake(0,90, 320, 326)];
        [mainView addSubview:_tableTeams];
        _tableTeams.delegate=self;
        _tableTeams.dataSource=self;
        _tableTeams.tag=2;





        /*
        _tableSchedule=[[UITableView alloc]initWithFrame:CGRectMake(0,90, 320, 326)];
        [mainView addSubview:_tableSchedule];
        _tableSchedule.delegate=self;
        _tableSchedule.dataSource=self;
        _tableSchedule.tag=2;
         */

         AdWhirlView *adWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
         adWhirlView.frame=CGRectMake(0, 430, 320, 50);
         [mainView addSubview:adWhirlView];

        CGRect frame = self->mainView.frame;
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
        [UIView beginAnimations:@"slideMenu" context:( void *)(self->mainView1)];
    mainView.hidden=NO;
        if(menuOpen) {
            frame.origin.x = 160;
            menuOpen = NO;
        }
        else
        {
            frame.origin.x = 0;
            menuOpen =YES;
        }

        self->mainView.frame = frame;
        [UIView commitAnimations];
    }
    else if (btn.tag==2)
    {

    }


    NSLog(@"Menu tapped");

}
4

0 に答える 0