How to Dismiss all UIAlertView when application enter to background in iOS


In ViewController.m or Appdelegate.m

-(void)viewDidLoad
{
[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}

In AppDelegate

- (void)applicationDidEnterBackground:(NSNotification *)theNotification
{
NSInteger cancelButtonIndex = self.alertView.cancelButtonIndex;
[self.alertView dismissWithClickedButtonIndex:cancelButtonIndex
animated:NO];
}

– How to make an iOS App
ktrkathir

How to load data faster in UITableView in iOS


Use performSelectorOnMainThread method

eg:

[tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];

– How to make an iOS App
ktrkathir

How to call the function when app will enter Foreground in iOS


Call a Function When Application will enter Foreground in iOS

NOTE:   Use NSNotificationCenter and Notify the App will Become the Foreground and Call a function

// AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application
{
 NSLog(@"app will enter foreground");
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"app did become active");
}
// ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"view did load");

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)appDidBecomeActive:(NSNotification *)notification {
NSLog(@"did become active notification");
}

- (void)appWillEnterForeground:(NSNotification *)notification {
NSLog(@"will enter foreground notification");
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"view will appear");
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"view did appear");
}

-How to make an iOS App
ktrkathir

Detect UIDevice Orientation in iOS


This is the Code to Detect the UIDevice Orientation statue in iOS

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];

– (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:{
/* start special animation */

Status.text =@”Portrait Orientation”;
break;
}

case UIDeviceOrientationPortraitUpsideDown:{
/* start special animation */

Status.text =@”Portrait Up Orientation”;
break;
}
case UIDeviceOrientationLandscapeLeft:{
/* start special animation */

Status.text =@”Landscape Left Orientation”;

break;
}
case UIDeviceOrientationLandscapeRight:{
/* start special animation */

Status.text =@”Landscape Right Orientation”;
break;
}

default:
break;
};
}

iOS Simulator Screen Shot -1
iOS Simulator Screen Shot -1

 

iOS Simulator Screen Shot-2
iOS Simulator Screen Shot -2

 

iOS Simulator Screen Shot -3
iOS Simulator Screen Shot -3

Download here

-ktrkathir

How to get Notification whether Keyboard is showing or not in iOS


//Get Notification whether Keyboard is showing or not
 [self registerForKeyboardNotifications];
#pragma mark - Notify Keyboard is Showing / Hiding
 - (void)registerForKeyboardNotifications
 {
 // Call this method somewhere in your view controller setup code.
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
  
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
  
 }
#pragma mark - Handle Keyboard Notification

- (void)keyboardWasShown:(NSNotification*)aNotification
 {
 // Called when the UIKeyboardDidShowNotification is sent.
 //Create Animation Block for UIView

//NSDictionary* info = [aNotification userInfo];
 //CGRect beginFrame = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
 //CGRect endFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
 //DebugLog(@"beginFrame %f",beginFrame.size.height);
 //DebugLog(@"endFrame %f",endFrame.size.height);
 }
 - (void)keyboardWillBeHidden:(NSNotification*)aNotification
 {
 // Called when the UIKeyboardWillHideNotification is sent
 }

– How to make an iOS App
ktrkathir