在同一视图中创建新表时表视图标记问题

时间:2013-08-09 13:08:57

标签: iphone ios uitableview

我有UITableView标签1.当我删除此表时,再次创建一个带有标签2的新表,它在模拟器中挂起,没有任何动作发生。如果我用相同的标签1创建它的ok.any身体帮助我吗?

我的代码如下。

- (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");

}

0 个答案:

没有答案