Search the content of a UITableView in iphone?

Step 1: Create a Window base application using template . Give the application name “SearchTable”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: Now we’ll add UITableViewController class and NSObject class to the project. Choose New file -> Select cocoa touch classes group and then selectUITableViewController and NSObject . Give the name of the class MainView and Product. Create a MainView.xib file in the resource folder.
Step 4: In the AppDelegate.h file  we have added UINavigationController in the file. So make the following changes in the file.
@interface SearchTableAppDelegate : NSObject  <UIApplicationDelegate> {
   UIWindow
 *window;
   UINavigationController      
 *navController;
}
   
@property (nonatomic, retain) IBOutlet UIWindow *window;
   
@property (nonatomic, retain) IBOutlet UINavigationController       *navController;
Step 5:  In the MainView.h file we make the following changes:
@interface MainView : UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>  {
  NSArray                       *listContent;
 
 NSMutableArray        *filteredListContent;
 
 NSString              *savedSearchTerm;
  NSInteger             savedScopeButtonIndex;
 
 BOOL                  searchWasActive;
}
  @property (nonatomic, retain) NSArray *listContent;
 
 @property (nonatomic, retain) NSMutableArray *filteredListContent;
  @property (nonatomic, copy) NSString *savedSearchTerm;
 
 @property (nonatomic) NSInteger savedScopeButtonIndex;
 
 @property (nonatomic) BOOL searchWasActive;
Step 6: Double click your MainView.xib file open it to the Interface Builder. Drag Search Display from the library and place it to the main window. Drag search bar from the library and place it on the table view. Now select search display icon from the main window and bring up connection inspector and select searchBar to the SearchBar. Save it and go back to the Xcode.
Step 7: In the AppDelegate.m file make the following changes:
(void)applicationDidFinishLaunching:(UIApplication *)application
{
       
 NSArray *listContent = [[NSArray alloc] initWithObjects:
       
 [Product productWithType:@"Device" name:@"iPhone"],
       
 [Product productWithType:@"Device" name:@"iPod"],
       
 [Product productWithType:@"Device" name:@"iPod touch"],
       
 [Product productWithType:@"Desktop" name:@"iMac"],
       
 [Product productWithType:@"Desktop" name:@"Mac Pro"],
       
 [Product productWithType:@"Portable" name:@"iBook"],
       
 [Product productWithType:@"Portable" name:@"MacBook"],
       
 [Product productWithType:@"Portable" name:@"MacBook Pro"],
       
 [Product productWithType:@"Portable" name:@"PowerBook"], nil];
       
 
       
 
        MainView
 *mainViewController = [[MainView alloc]initWithNibName:@"MainView" bundle:nil];
        mainViewController.listContent
 = listContent;
       
 [listContent release];
       
 
        UINavigationController
 *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
        self.navController
 = navigationController;
       
 [navigationController release];
       
 [window addSubview:navController.view];
       
 [window makeKeyAndVisible];
}
Step 8: In the MainView.m file make the following changes:
(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
   
[self.filteredListContent removeAllObjects]; 
   
 for (Product *product in listContent)
 
 {
   
 if ([scope isEqualToString:@"All"] || [product.type isEqualToString:scope])
     
{
        NSComparisonResult result
 = [product.name compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)range:NSMakeRange(0, [searchText length])];
       
 if (result == NSOrderedSame)
       
 {
         
[self.filteredListContent addObject:product];
         
}
     
 }
   
}
}
(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
 
 [self filterContentForSearchText:searchString scope:
   
[[self.searchDisplayController.searchBar scopeButtonTitles]objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
   
 
}
(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
   
 [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
   
 [[self.searchDisplayController.searchBar scopeButtonTitles]objectAtIndex:searchOption]];
     
}
Step 9: For the Product.m file make the following changes:

(id)productWithType:(NSString *)type name:(NSString *)name
{
  Product
 *newProduct = [[[self alloc] init] autorelease];
  newProduct.type
 = type;
  newProduct.name
 = name;
 
 return newProduct;
}
(void)dealloc
{
       
 [type release];
       
 [name release];
       
 [super dealloc];
}
Step 10: Compile and run the application on the simulator.


How to change Language in iPhone?

In this example we will see how to change the language in the iPhone using .xib file. If we change the language into the French from the settings of iPhone, then run the application it will translate the text into the French language. So let see how it will be worked.
Step 1: Create a View base application using template. Give the application name “LanguageChange”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: Expand classes and notice Interface Builder created the LanguageChangeViewController class for you. Expand Resources and notice the template generated a separate nib, LanguageChangeViewController.xib, for the “LanguageChange”.
Step 4: In the LanguageChangeAppDelegate.. file make the following changes in the file:
(void)applicationDidFinishLaunching:(UIApplication *)application {

  UINavigationController
 *navigationController = [[UINavigationController   alloc] initWithRootViewController:viewController];
 
 [window addSubview:navigationController.view];
 
 [window makeKeyAndVisible];
}
Step 5: Select the NIB files from the Groups & Files, right click on LanguageChangeViewController.xib file and select Get Info . Select General tab and click on “Add Localization” in bottom left. In popup type fr then select Add button. You will see fr will be added in Info window.Then you will see there are two .ib files are available one LanguageChangeViewController.xib(en) and another LanguageChangeViewController.xib(fr) file added in the NIB file.
Step 6: Double click Your LanguageChangeViewController.xib(en) file and open it to the Interface Builder. Open the View window and drag the label from the library and place it to the View window. Select the label from the View window and bring up Attribute Inspector and change the text(See the figure1). Connect File’s Owner icon to the View icon and select the view. Now save the .xib(en) file, close it and go back to
Step 7: Now open the LanguageChangeViewController.xib(fr) file and open it to the Interface Builder. Open the View window and drag the label from the library and place it to the View window. Select the label from the View window and bring up Attribute Inspector and change the text into french language (See the figure2) (You can use google translator). Connect File’s Owner icon to the View icon and select the view. Now save the .xib(fr) file, close it and go back to the Xcode.
Step 8: Open the LanguageChangeViewController.m file and make the following changes in the file:
(void)viewDidLoad {
  NSLocale *language = [NSLocale currentLocale];
  NSString *titleOFApplication = [language   displayNameForKey:NSLocaleIdentifier   value:[language localeIdentifier]];
  self.title = titleOFApplication;
  [super viewDidLoad];
}

Step 9: Its all done , now just compile and run the application in the Simulator (See the figure 3). Simulator will show you the text in english.




 
Step 10: If you want to see output in french language then select the setting application from the iPhone -> General ->International ->  Language -> select french language and save it. Now run the application, you will see the output in French language.




What is atomic and nonatomic in iPhone SDk?


The last two are identical; "atomic" is the default behavior (note that it is not actually a keyword; it is specified only by the absence of nonatomic).
Assuming that you are @synthesizing the method implementations, atomic vs. non-atomic changes the generated code. If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory.
With "atomic", the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.
In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".
What "atomic" does not do is make any guarantees about thread safety. If thread A is calling the getter simultaneously with thread B and C calling the setter with different values, thread A may get any one of the three values returned -- the one prior to any setters being called or either of the values passed into the setters in B and C. Likewise, the object may end up with the value from B or C, no way to tell.
Ensuring data integrity -- one of the primary challenges of multi-threaded programming -- is achieved by other means.

UITextFieldDelegate in iphone sdk


- (void)viewWillAppear:(BOOL)animated
{
 [super viewWillAppear:animated];

 [[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(keyboardWillShow:) 
              name:UIKeyboardWillShowNotification object:self.view.window];
 [[NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(keyboardWillHide:) 
              name:UIKeyboardWillHideNotification object:self.view.window];

}
- (void)viewWillDisappear:(BOOL)animated{

 [self setEditing:NO animated:YES];
 // unregister for keyboard notifications while not visible.

 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
 [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark - UIViewController delegate methods

- (void) keyboardWillShow:(NSNotification *)notif{
    // The keyboard will be shown. If the user is editing the comments, adjust the display so that the
    // comments field will not be covered by the keyboard.

 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.3];
 CGRect rect = self.view.frame;
 rect.origin.y = self.view.frame.origin.y - 200;
 self.view.frame = rect;
 [UIView commitAnimations];


}

- (void) keyboardWillHide:(NSNotification *)notif{
    // The keyboard will be hidden.
    // view should be shifted donw to its real position.

 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.3];
 CGRect rect = self.view.frame;
 rect.origin.y = self.view.frame.origin.y + 200;
 self.view.frame = rect;
 [UIView commitAnimations];
 
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
 [textField resignFirstResponder];
 return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {        
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    return !([newString length] >124);


 /*
 if(textField.tag==1)
 {
  //return integer
  NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
  [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
  NSNumber* candidateNumber;
  NSString* candidateString = [amendment.text stringByReplacingCharactersInRange:range withString:string];
  range = NSMakeRange(0, [candidateString length]);
  [numberFormatter getObjectValue:&candidateNumber forString:candidateString range:&range error:nil];
 
  if (([candidateString length] > 0) && (candidateNumber == nil || range.length < [candidateString length])) {
  
   return NO;
  }
  else 
  {
   return YES;
  }
 
 
 
 }
 else
 {
  NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  return !([newString length] >500);
 }
 */

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
 NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    return !([newString length] >124);

 if ([text isEqualToString:@"\n"])
 {
  [textView resignFirstResponder];
  return FALSE;
 }

 return TRUE;
}

how To Add sound in iphone/ipad ?


first add Frameworks (AVFoundation.framework)

and import:

#import <AVFoundation/AVFoundation.h>

- (void)viewDidLoad {
    [super viewDidLoad];


NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Sound.mp3", [[NSBundle mainBundle] resourcePath]]];
   AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
   audioPlayer.numberOfLoops =0;
   [audioPlayer play];

}

iOS 6.X SDK release history

                                       Table of versions: iOS 6.x SDK

Version
Release date
Xcode version
iOS 6.0 beta 1
June 11, 2012
Xcode 4.5 Beta preview

iOS 6.0 beta 2

June 25, 2012
Xcode 4.5 Beta 2 preview

iOS 6.0 beta 3

July 16, 2012
Xcode 4.5 Beta 3 preview

iOS 6.0 beta 4


August 6, 2012
Xcode 4.5 Developer Preview

iOS 6.0 Golden Master

September 12, 2012
Xcode 4.5 Golden Master

iOS 6.0 Final


September 19, 2012
Xcode 4.5

iOS 6.1 beta 1

November 1, 2012
Xcode 4.6

iOS 6.1 beta 2


November 12, 2012
Xcode 4.6

iOS 6.1 beta 3

December 3, 2012
Xcode 4.6

iOS 6.1 beta 4


December17,2012
Xcode 4.6

iOS 6.1

January 26, 2013
Xcode 4.6