Thursday 9 June 2011

How to Show a OneTime SubView On The MainView

#import

@interface Home : UIView
{
}
@end

#import "Home.h"

@implementation Home

- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
- (void)dealloc
{
[super dealloc];
}
@end

#import
@interface AgentWorldViewController : UITabBarController
{
UIView *HomePage;
}
-(void)RemoveHomePageView;

@end

#import "AgentWorldViewController.h"
#import "Home.h"
#import "AgentClosest.h"
#import "BuzzView.h"
#import "SocialMedia.h"

@implementation AgentWorldViewController

- (void)viewDidLoad
{
[super viewDidLoad];
//Create view for find an Agent
UINavigationController *agentNC = [[UINavigationController alloc] init];
AgentClosest *agentVC = [[AgentClosest alloc] init];
agentVC.tabBarItem.title = @"Find an Agent";
agentVC.tabBarItem.image = [UIImage imageNamed:@"Newnavigation_findAgent.png"];
agentVC.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Newbackground.png"]];
agentNC.viewControllers = [NSArray arrayWithObjects:agentVC, nil];
agentNC.navigationBar.barStyle = UIBarStyleBlackTranslucent;

//Create view for Real Estate News
UINavigationController *oBuzzNC = [[UINavigationController alloc]init];
BuzzView *oBuzz = [[BuzzView alloc] init];
oBuzz.tabBarItem.title = @"Real Estate News";
oBuzz.tabBarItem.image = [UIImage imageNamed:@"Newnavigation_rNews.png"];
oBuzz.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Newbackground.png"]];
oBuzzNC.viewControllers = [NSArray arrayWithObjects:oBuzz, nil];
oBuzzNC.navigationBar.barStyle = UIBarStyleBlackTranslucent;

//Create view for Social Media and Network
UINavigationController *oSettingNC = [[UINavigationController alloc] init];
SocialMedia *oSetting = [[SocialMedia alloc] init];
oSetting.tabBarItem.title = @"Social Media";
oSetting.tabBarItem.image = [UIImage imageNamed:@"Newnavigation_settings.png"];
oSetting.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"NewdistSettings_background.png"]];
oSettingNC.viewControllers = [NSArray arrayWithObjects:oSetting, nil];
oSettingNC.navigationBar.barStyle = UIBarStyleBlackTranslucent;

self.viewControllers = [NSArray arrayWithObjects:agentNC, oBuzzNC, oSettingNC, nil];
[agentNC release];
[agentVC release];
[oBuzz release];
[oSetting release];

self.tabBarItem=[[UITabBarItem alloc]initWithTabBarSystemItem: UITabBarSystemItemBookmarks tag:0];

CGRect apprect = [[UIScreen mainScreen] applicationFrame];
HomePage = [[UIView alloc] initWithFrame:apprect];
UIImageView *HomePageBackgroud = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Newbackground.png"]];
HomePageBackgroud.frame = apprect;
[self.view addSubview:HomePageBackgroud];
[HomePageBackgroud release];

UIButton *btnFindAgent = [UIButton buttonWithType:UIButtonTypeCustom];
[btnFindAgent setImage:[UIImage imageNamed:@"Newhome_findAgent.png"] forState:UIControlStateNormal];
[btnFindAgent setFrame:CGRectMake(120.0f, 90.0f, 64.0f, 64.0f)];
btnFindAgent.tag = 0;
[btnFindAgent addTarget:self action:@selector(HomePageButton_Click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnFindAgent];

UILabel *findAgentlbl=[[UILabel alloc]initWithFrame:CGRectMake(117.0f, 160.0f, 80.0, 10.0)] ;
findAgentlbl.text=@"Find an Agent";
[findAgentlbl setBackgroundColor:[UIColor clearColor]];
findAgentlbl.font=[UIFont fontWithName:@"Helvetica-Bold" size:10];
findAgentlbl.textColor=[UIColor whiteColor];
[self.view addSubview:findAgentlbl];
[findAgentlbl release];

UIButton *btnRealStateNews = [UIButton buttonWithType:UIButtonTypeCustom];
[btnRealStateNews setImage:[UIImage imageNamed:@"Newhome_rNews.png"] forState:UIControlStateNormal];
[btnRealStateNews setFrame:CGRectMake(120.0f, 205.0f, 64.0f, 64.0f)];
btnRealStateNews.tag =1;
[btnRealStateNews addTarget:self action:@selector(HomePageButton_Click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnRealStateNews];

UILabel *RealStatelbl=[[UILabel alloc]initWithFrame:CGRectMake(110.0, 275.0, 90.0, 10.0)];
RealStatelbl.text=@"Real Estate News";
[RealStatelbl setBackgroundColor:[UIColor clearColor]];
RealStatelbl.font=[UIFont fontWithName:@"Helvetica-Bold" size:10];
RealStatelbl.textColor=[UIColor whiteColor];
[self.view addSubview:RealStatelbl];
[RealStatelbl release];

UIButton *btnSetting = [UIButton buttonWithType:UIButtonTypeCustom];
[btnSetting setImage:[UIImage imageNamed:@"Newhome_settings.png"] forState:UIControlStateNormal];
[btnSetting setFrame:CGRectMake(120.0f, 325.0f, 64.0f, 64.0f)];
btnSetting.tag = 2;
[btnSetting addTarget:self action:@selector(HomePageButton_Click:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnSetting];
}

- (void)InfoButton:(id)sender
{
InfoViewController *infocontroller=[[InfoViewController alloc]init];
[self presentModalViewController:infocontroller animated:YES];
}
- (void)HomePageButton_Click:(id)sender
{
UIButton *btnTemp = sender;
if (btnTemp.tag == 0)
{
self.selectedIndex = 0;
[self RemoveHomePageView];
}
else if (btnTemp.tag == 1)
{
self.selectedIndex = 1;
[self RemoveHomePageView];
}
else
{
self.selectedIndex = 2;
[self RemoveHomePageView];
}
}

-(void)RemoveHomePageView
{

UIImageView *vHomePage;
UIButton *bButton;
UILabel *lLabel;
for (NSInteger i=[[self.view subviews] count] -1 ; i>= 0; i--)
{
if ([[[self.view subviews] objectAtIndex:i] isKindOfClass:[UIImageView class]])
{
vHomePage=[[self.view subviews] objectAtIndex:i];
[vHomePage removeFromSuperview];
vHomePage=nil;
}
else if ([[[self.view subviews] objectAtIndex:i] isKindOfClass:[UIButton class]])
{
bButton = [[self.view subviews] objectAtIndex:i];
[bButton removeFromSuperview];
bButton = nil;
}
else if ([[[self.view subviews] objectAtIndex:i] isKindOfClass:[UILabel class]])
{
lLabel = [[self.view subviews] objectAtIndex:i];
[lLabel removeFromSuperview];
lLabel = nil;
}

}

}
- (IBAction)RealStateNews
{

}
- (void) locationManager: (CLLocationManager *) manager didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *) oldLocation
{

NSString *lat = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];

NSLog(lat);
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];

NSLog(lng);
NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];

NSLog(acc);

[acc release];
[lat release];
[lng release];

MKCoordinateSpan span;
span.latitudeDelta=newLocation.coordinate.latitude;
span.longitudeDelta=newLocation.coordinate.longitude;

MKCoordinateRegion region;
region.center = newLocation.coordinate;
region.span=span;
}
- (void) locationManager: (CLLocationManager *) manager didFailWithError: (NSError *) error
{
NSString *msg = [[NSString alloc] initWithString:@"Error obtaining location"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:msg delegate:nil cancelButtonTitle: @"Done" otherButtonTitles:nil];
[alert show];
[msg release];
[alert release];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

- (void)viewDidUnload
{
}
- (void)dealloc
{
[HomePage release];
[super dealloc];
}

@end

No comments:

Post a Comment