Friday 9 August 2013

Table view tag issue while create new table in same view

Table view tag issue while create new table in same view

Hi i have a table view with tag 1.When i remove this table and again
create same new table with tag 2 its hang in simulator nothing action
happen.While if i create with same tag 1 its ok.any body help me? sorry
for my bad english.
my code is below.
- (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");
}

No comments:

Post a Comment