My Connections

Business card

Wednesday, July 14, 2010

How to disable navigation bar

self.navigationController.navigationBar.userInteractionEnabled = NO;

Friday, July 9, 2010

Location Manager Delegate methods.....

-(IBAction)btn_Clicked:(id)sender
{
if(locationManager.locationServicesEnabled)
{
[spinner startAnimating];
btn.enabled = NO;
[locationManager startUpdatingLocation];
}
}

#pragma mark -
#pragma mark Geo Points methods

//It will be called whenever the device is able to detect GPS locations.....

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if(newLocation != nil)
appDelegate.currentLocation = newLocation;
else
appDelegate.currentLocation = oldLocation;

[locationManager stopUpdatingLocation];
btn.enabled = YES;
[spinner stopAnimating];

UIMyViewController *myViewController = [[UIMyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self.navigationController pushViewController:myViewController animated:YES];
[stateViewController release];
}


//It will be called when device will fail to get GPS location and will show a popup with "Don't Allow" and "Ok" button.....

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
[locationManager stopUpdatingLocation];
btn.enabled = YES;
[spinner stopAnimating];

UIMyViewController *myViewController = [[UIMyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self.navigationController pushViewController:myViewController animated:YES];
[stateViewController release];

/*if (error.code == kCLErrorDenied)
{
// User denied access to location service
printf("\n\n Don't Allow Clicked.");
}
else if (error.code == kCLErrorLocationUnknown)
{
// User denied access to location service
printf("\n\n OK Clicked.");
}
else if (error.code == kCLErrorNetwork)
{
// User denied access to location service
printf("\n\nmy error kCLErrorNetwork.");
}
else if (error.code == kCLErrorHeadingFailure)
{
// User denied access to location service
printf("\n\nmy error kCLErrorHeadingFailure.");
}*/
}

How to rotate compaas needle manually....

#define RadiansTodegrees(Y) ( 180.0* Y / 3.14)

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
theEndPoint = [touch locationInView:self.view];
if((theEndPoint.x>My_Compass.frame.origin.x && theEndPoint.y>My_Compass.frame.origin.y) && (theEndPoint.x {
float Centre_X = My_Compass.frame.origin.x + (My_Compass.frame.size.height/2);
float Centre_Y = My_Compass.frame.origin.y + (My_Compass.frame.size.width/2);

float dx=theEndPoint.x-Centre_X;
float dy=theEndPoint.y-Centre_Y;

double angle=atan2(dy,dx);
double br = RadiansTodegrees(angle);

CGAffineTransform rotate = CGAffineTransformMakeRotation(((br+90)/180)*3.14);
[Niddel setTransform:rotate];

}

}

Wednesday, July 7, 2010

How to validate an email id..?

Way 1.

NSString *email = textFieldemail.text;
NSString *emailRegEx =
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";

NSPredicate *regExPredicate =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:email];


if(!myStringMatchesRegEx)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"email" message:@"Email id is invalid, please provide a valid email id." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
[self prepareHmlDataAndSendEmail];

Way 2.

if (! (([txtMailId.text rangeOfString:@"@"].location != NSNotFound) && ([txtMailId.text rangeOfString:@"."].location != NSNotFound) && [txtMailId.text rangeOfString:@"@"].location < [txtMailId.text rangeOfString:@"."].location ) )
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"email" message:@"Email id is invalid, please provide a valid email id." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
[self prepareHmlDataAndSendEmail];

Way 3.
NSArray *validateAtSymbol = [txtLoginId.text componentsSeparatedByString:@"@"];
NSArray *validateDotSymbol = [txtLoginId.text componentsSeparatedByString:@"."];
if(([validateAtSymbol count] != 2) || ([validateDotSymbol count] < 2))
{      
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Invalid EMail Address" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertView show];
[alertView release];
}

Thursday, July 1, 2010

Location Manager for compass movment n to call methods on changing angle from one quater to another.

class.h

@interface class : UIViewController
{
CLLocationManager *locationManager;
}

class.m


#pragma mark -
#pragma mark Geo Points methods

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if(newLocation != nil)
currentLocation = newLocation;
else
currentLocation = oldLocation;

[self btn_POIStartClicked];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
/*NSString *msg=[NSString stringWithFormat:@"New magnetic heading: %f and New true heading: %f. ",newHeading.magneticHeading,newHeading.trueHeading];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
NSLog(@"New true heading: %f", newHeading.trueHeading);
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);*/
int angle = newHeading.magneticHeading;
CGAffineTransform rotate = CGAffineTransformMakeRotation( newHeading.magneticHeading/180*3.14 );
[compassView setTransform:rotate];

if(oldAngel != (angle/90))
{
switch (angle/90)
{
case 0:
{

}
break;
case 1:
{

}
break;
case 2:
{

}
break;
case 3:
{

}
break;
}
}
}

Customize view on Camera View.

STEPS:

step 1. Load the xib which will contain camera view...
step 2. Now load camera on that xib.
step 3. Now load the view (addSubView) on camera.cameraOverlayView.

camera.m


//********************************* CAMERA VIEW CODE*******************************
camera = [[UIImagePickerController alloc] init];
camera.view.backgroundColor = [UIColor clearColor];
overView.frame = CGRectMake(0,44,320,416);
nvgView.frame = CGRectMake(0,0,320,44);

// [camera.view addSubview:overView];
// [camera.view addSubview:nvgView];


// Hide Apple's UI.
#if TARGET_IPHONE_SIMULATOR
camera.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;

[camera.view addSubview:overView];
[camera.view addSubview:nvgView];

#elif TARGET_OS_IPHONE
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.wantsFullScreenLayout = YES;
camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform, 2.0f, 2.0f);

// Add the view to be overlaid
//camera.cameraOverlayView = overView;
[camera.cameraOverlayView addSubview:flipView];
[camera.cameraOverlayView addSubview:nvgView];

#endif

// Show the camera's view as a modal dialog.
[self presentModalViewController:camera animated:YES];
[self.view addSubview:camera.view];
//********************************** CAMERA VIEW END*******************************

Page controller with scroll view (first xib in another xib)

outer.h

@interface outer : UIViewController {

NSInteger kNumberOfPages;
NSInteger selectedPage;
NSArray* arrRepList;

IBOutlet UIPageControl* pageControl;
IBOutlet UIScrollView* scrollView;

NSMutableArray *viewControllers;
//BOOL pageControlUsed;
}

@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIPageControl *pageControl;
@property (nonatomic, retain) NSMutableArray *viewControllers;

- (IBAction)changePage:(id)sender;

@end


outer.m

@interface outer (PrivateMethods)

- (void)loadScrollViewWithPage:(int)page;
- (void)scrollViewDidScroll:(UIScrollView *)sender;

@end

@implementation outer

- (void)viewDidLoad {
[super viewDidLoad];
kNumberOfPages = 7;
self.title = @"Outer XIB";

// view controllers are created lazily
// in the meantime, load the array with placeholders which will be replaced on demand
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];

// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;

pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = selectedPage;
[pageControl setFrame:CGRectMake(pageControl.frame.origin.x,pageControl.frame.origin.y,pageControl.frame.size.width,pageControl.frame.size.height*(3.0/4.0))];
//CGRect tmp=CGRectMake(320*selectedPage, 0,320,305 );
//[scrollView scrollRectToVisible:tmp animated:YES];
[self changePage:nil];

}

- (void)loadScrollViewWithPage:(int)page {
if (page < 0) return;
if (page >= kNumberOfPages) return;

// replace the placeholder if necessary
UIRepDetailsViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
controller = [[UIRepDetailsSubView alloc] initWithPageNumber:page andRepList:arrRepList];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}

// add the controller's view to the scroll view
if (nil == controller.view.superview) {
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
}

- (void)scrollViewDidScroll:(UIScrollView *)sender {
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
/*if (pageControlUsed) {
// do nothing - the scroll was initiated from the page control, not the user dragging
return;
}*/
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;

// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadScrollViewWithPage:page - 2];
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];
[self loadScrollViewWithPage:page + 2];
// A possible optimization would be to unload the views+controllers which are no longer visible
}

// At the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//pageControlUsed = NO;
}

- (IBAction)changePage:(id)sender {
int page = pageControl.currentPage;

// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadScrollViewWithPage:page - 2];
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];
[self loadScrollViewWithPage:page + 2];
// update the scroll view to the appropriate page
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[scrollView scrollRectToVisible:frame animated:YES];
// Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above.
//pageControlUsed = YES;
}





inner.h

/* all declarations */
int pageNumber;
NSArray* arrRepList;

inner.m

static NSArray *__pageControlColorList = nil;

@implementation inner

// Creates the color list the first time this method is invoked. Returns one color object from the list.
+ (UIColor *)pageControlColorWithIndex:(NSUInteger)index {
if (__pageControlColorList == nil) {
__pageControlColorList = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor magentaColor],
[UIColor blueColor], [UIColor orangeColor], [UIColor brownColor], [UIColor grayColor], nil];
}
// Mod the index by the list length to ensure access remains in bounds.
return [__pageControlColorList objectAtIndex:index % [__pageControlColorList count]];
}

// Load the view nib and initialize the pageNumber ivar.
- (id)initWithPageNumber:(int)page andRepList:(NSArray*) repList{
if (self = [super initWithNibName:@"RepDetailsSubView" bundle:nil]) {
pageNumber = page;
arrRepList = repList;
}
return self;
}

Keyboard adjustment while typing in a textfield

- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self setViewMovedUp:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self setViewMovedUp:NO];
return YES;
}

- (void)setViewMovedUp:(BOOL)movedUp{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
// Make changes to the view's frame inside the animation block. They will be animated instead
// of taking place immediately.
CGRect rect = self.view.frame;
if (movedUp){
// If moving up, not only decrease the origin but increase the height so the view
// covers the entire screen behind the keyboard.
//rect.origin.y -= kOFFSET_FOR_KEYBOARD;
//rect.size.height += kOFFSET_FOR_KEYBOARD;
if(rect.origin.y ==0)
rect.origin.y = self.view.frame.origin.y - 165;
}
else{
// If moving down, not only increase the origin decrease the height.
//rect.origin.y += kOFFSET_FOR_KEYBOARD;
//rect.size.height -= kOFFSET_FOR_KEYBOARD;
if(rect.origin.y <0)
rect.origin.y = self.view.frame.origin.y + 165;
}

self.view.frame = rect;
[UIView commitAnimations];
}

How to Change String format from "48821869.89" to "48,821,869.89"

-(NSString*)convertStringInCommaFormat:(NSString*) inputStr
{
double strInDouble = [inputStr doubleValue];
int strInInt = strInDouble;
float strFloatingPart = strInDouble - strInInt;
NSString* temp = [NSString stringWithFormat:@"%d",strInInt];
int check = [temp length] % 3;

NSString* strFinal= @"";
if(check != 0)
{
NSString* ch =[temp substringWithRange:NSMakeRange(0, check)];
strFinal = [strFinal stringByAppendingString:[NSString stringWithFormat:@"%@,",ch]];
}
for(int k = 0 ; k<[temp length]/3 ; k++)
{
NSString* ch =[temp substringWithRange:NSMakeRange(check, 3)];
strFinal = [strFinal stringByAppendingString:[NSString stringWithFormat:@"%@,",ch]];
check = check+3;
}

NSString* final = [strFinal substringWithRange:NSMakeRange(0, [strFinal length] - 1)];
NSString* strTemp = [NSString stringWithFormat:@"%0.2f",strFloatingPart];
NSString* strAfterDot = [strTemp substringWithRange:NSMakeRange(1, [strTemp length] - 1)];
final = [final stringByAppendingString:[NSString stringWithFormat:@"%@",strAfterDot]];

return final;
}