Thursday 31 January 2013

set the background image on UIToolBar and also set an image in fix coordinate on UIToolBar


UIToolbar *tb=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 420, 320, 44)];
[self.view addSubview:tb];
[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"manoj.png"] forToolbarPosition:UIToolbarPositionAny/Bottom barMetrics:UIBarMetricsDefault];
UIImageView *img11=[[UIImageView alloc]initWithFrame:CGRectMake(200, 5, 100, 35)];
img11.backgroundColor=[UIColor clearColor];
img11.image=[UIImage imageNamed:@"kanishka.png"];
[tb addSubview:img11];

set the background image on UINavigationBar and also set an image in fix coordinate on UINavigationBar


UINavigationBar *nav=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:nav];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"manoj.png"]forBarMetrics:UIBarMetricsDefault];
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(200, 5, 100, 35)];
img.backgroundColor=[UIColor clearColor];
img.image=[UIImage imageNamed:@"kanishka.png"];
[nav addSubview:img];

Wednesday 30 January 2013

How to open a location using google map by passing the location name


- (void)viewDidLoad
{
NSString* address = @"Phulpur,Allahabad,Uttar Pradesh,India";
    
NSString* searchQuery =  [address stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
//open the specified location on googleMap
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
[super viewDidLoad];
}

How to reload table view data from custom table cell view in iPhone?

Often we create a custom table cell view for our table view cells and if we are required to reload our table view from our custom table cell view's method then we can do it using the following.
syntax:
UITableView *tableView = (UITableView *) self.superview;
[tableView reloadData];

Thursday 24 January 2013

important url for iPhone

1- http://www.iphonesdkarticles.com/2009/01/uitableview-indexed-table-view.html

2-http://epiicdream.wordpress.com/2012/02/27/ios-sdk-savingretrieving-data-using-nsuserdefaults/

3-http://www.mindfiresolutions.com/Merging-Two-Videos--iPhoneiPad-Tip--1396.php

iPhone project has “My Mac 64-bit”


Right-click on the xcodeproj file and select "show package contents."
Make a backup copy of the xcuserdata folder.
Now delete everything inside the xcuserdata folder, and restart xcode.
If causes a problem, then put backup folder back in.
thanks

Wednesday 23 January 2013

Remove in NSUserDefault


[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"MyKey"];
//dont forget to write
[[NSUserDefaults standardUserDefaults]synchronize ];

save and get image in NSUserDefault


save image:-
 UIImageView *
contactImageView;
UIImage *contactImage = contactImageView.image;
NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:imageData forKey:@"image"];
OR
[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(
contactImage)
forKey:@"imageKey"];
//choose image from Library
- (IBAction)chooseImage:(id)sender {
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
{

    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}
#pragma mark - Image Picker Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
contactImageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
  
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
  
[picker dismissModalViewControllerAnimated:YES];
}

code for get image:

-(IBAction)getImage:(id)sender
{
UIImageView *contactImageView1=[[UIImageView alloc]initWithFrame:CGRectMake(x,y,w,h)];
[self.view addSubview:contactImageView1];
NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
UIImage* image = [UIImage imageWithData:imageData];
contactImageView1.image=image;
}

NSUserDefaults Class?



With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”. The iOS defaults system is available throughout all of the code in your app, and any data saved to the defaults system will persist through application sessions. This means that even if the user closes your application or reboots their phone, the saved data will still be available the next time they open the app!

With NSUserDefaults you can save objects from the following class types:
  • NSData
  • NSString
  • NSNumber
  • NSDate
  • NSArray
  • NSDictionary
If you want to store any other type of object, such as a UIImage, you will typically need to archive it or wrap it in an instance of NSData, NSNumber, or NSString.
Now that you know a bit about what can be done with NSUserDefaults, let’s jump into learning how to use the defaults system with a simple sample app that will store contact information.