Wednesday, 29 May 2013

TO sort a string separated by symbols and make array of values




 NSString *string = @"0|0,0,0|0,0,0,0,0";  // Need to short 
    
    NSArray *myArray = [string componentsSeparatedByString:@"|"] ;
    
    NSArray *bookNoArray;
    NSArray *activityArray;
    NSArray *noOfPagesArray;
    for(int i=0;i<[myArray count];i++)
    {
        if(i==0)
        {
            bookNoArray= [myArray[i] componentsSeparatedByString:@","];
        }
        if(i==1)
        {
            activityArray= [myArray[i] componentsSeparatedByString:@","];
        }
        if(i==2)
        {
            noOfPagesArray= [myArray[i] componentsSeparatedByString:@","];
        }
        
    }
    NSLog(@"bookNoArray: %@ activityArray: %@ noOfPagesArray:%@ ", bookNoArray,activityArray,noOfPagesArray);       // Sorted out put

To get device screen width and height iOS




    CGRect screenRect=[[UIScreen mainScreen]bounds];
    CGSize size=screenRect.size;
    screenWidth=size.width;

    screenHeight=size.height;

TO Clear UITextField Placeholder text on tap



TO add a placeholder text in UITextField


yourTextField.placeholder=@"User Name";

 To remove when tap 

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    textField.placeholder = nil;

}

TO remain a view always on top in Native COCOA


int x=1; // as per your views adjustment, increase value of x to remain your view on top      
            //always

yourView.layer.zPosition=x; 

Swipe gesture iOS


- (void)viewDidLoad
{
    [super viewDidLoad];


UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self  action:@selector(swipeMethod:)];

swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;

 [self.view addGestureRecognizer:swipeRecognizer];


}

-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
    NSLog(@"Swipe!");
// Perform actions
}

TO check device orientation when rotating device and need to change in views

iOS Development

Add below lines of code in your viewDidLoad method and perform action as required

- (void)viewDidLoad

{

[super viewDidLoad];

 [self setOrientation];

}

-(void)setOrientation
{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(deviceOrientationDidChangeNotification:)
     name:UIDeviceOrientationDidChangeNotification
     object:nil];
    
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        // portrait
        [self portraitView];
    } else {
        // landscape
        [self landscapeView];
    }
    

}

- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    if(orientation == 1 || orientation == 2) // Landscape
    {
        [self portraitView];
    }
    else if(orientation == 3 || orientation == 4) // Portrait
    {
        [self landscapeView];
    }
}


To check device orientation in viewDidLoad



Add below lines of code in -(void)viewDidLoad method

 UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
        // portrait
        
    } else {
        // landscape
        
    }