Tuesday, 13 August 2013

Go to particular parent class from subclass

you can find that particular UIViewController from its navigationController's viewControllers array like bellow...

    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[YourViewController class]]) {
            //Do not forget to import that YourViewController.h
            
            [self.navigationController popToViewController:controller
                                                  animated:YES];
            break;
        }

    }

Wednesday, 29 May 2013

Watch or counter with NSTimer

take object of NSTimer and also int variable  in .h file like bellow..

    NSTimer *timer;
    int hours, minutes, seconds;
    int secondsLeft;

and just use it with bellow method

- (void)updateCounter:(NSTimer *)theTimer {
    secondsLeft++;
    hours = secondsLeft / 3600;
    minutes = (secondsLeft % 3600) / 60;
    seconds = (secondsLeft %3600) % 60;
    //lblTime.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
    NSLog(@"\n%02d:%02d:%02d",hours,minutes,seconds);

}

-(void)countdownTimer{
    
    if([timer isValid])
    {
        [timer release];
    }
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
    [pool release];
}

See My Answer also converstion-of-seconds-in-minutes

Thursday, 18 April 2013

Convert some Special character to the Unicode/UTF 8 character and also Unicode to NSString....


    NSString *string = @"Hello & How % Are You?";
string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
string = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
string = [string stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];
    NSLog(@"\n\n ===>> Before ==>> %@",string);
    
    NSString *string2 = string;
string2 = [string2 stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
string2 = [string2 stringByReplacingOccurrencesOfString:@"%26" withString:@"&"];
string2 = [string2 stringByReplacingOccurrencesOfString:@"%25" withString:@"%"];    
    NSLog(@"\n\n ===>> After ==>> %@",string2);

Here you get out put is:

===>> Before ==>> Hello%20%25%20How%20Are%20You?
====>> After ==>> Hello % How Are You?

See My answer from this link.. http://stackoverflow.com/questions/16081390/how-to-get-from-web-service-in-iphone/16081968#16081968

And also list of Unicode/UTF 8 Character Table.. http://www.utf8-chartable.de/

Wednesday, 13 March 2013

Just Change your date from current format to another ...



I create this method for convert some string date format to convert in another format...

Call bellow method with its 3 parameters..


1. stringDate : Pass your date which in string type.
2. dateFormat : set format which is use in your passed string date. For ex if your string date is "14-03-2013 11:22 am" then set format @"dd-MM-yyyy hh:mm a".
3. getwithFormat : Set format which you want like if you want date "14/03/2013" then just set format @"dd/MM/yyyy".

How to call this see bellow example with method..

NSString *strSDate = [self changeDateFormat:@"14-03-2013 11:22 am" dateFormat:@"dd-MM-yyyy hh:mm a" getwithFormat:@"dd/MM/yyyy"];

Output is : 14/03/2013


-(NSString *)changeDateFormat:(NSString*)stringDate dateFormat:(NSString*)dateFormat getwithFormat:(NSString *)getwithFormat{
    
    
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:dateFormat];
    
    NSDate *date = [dateFormatter dateFromString:stringDate];
    
    dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:getwithFormat];
    
    NSString *convertedString = [dateFormatter stringFromDate:date];
    NSLog(@"Converted String : %@",convertedString);
    return convertedString;
}


Also Get Date in NSDate from NSString with my bellow custom Method...

-(NSDate *)convertStringToDate:(NSString *) date dateFormat:(NSString*)dateFormat{
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    NSDate *nowDate = [[[NSDate alloc] init] autorelease];
    [formatter setDateFormat:dateFormat];// set format here which format in string date
    date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""];
    nowDate = [formatter dateFromString:date];
    // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate);
    return nowDate;

}

and use it like bellow...

NSDate *startDate = [self convertStringToDate:@"2013-05-27 19:00" dateFormate:@"yyyy-MM-dd HH:mm"];
NSDate *endDate = [self convertStringToDate:@"2013-05-27 20:00" dateFormate:@"yyyy-MM-dd HH:mm"];

Sunday, 17 February 2013

not get iPhone simulator option on xcode? see this bellow answer

Some time you not seen the iPhone simulator option on xcode and just see the "Mac 64-bit" option.

so for get iPhone simulator option on xcode just change base SDK in project -> Build Setting and just set  "latest ios sdk" option instead of other.

Also see this bellow link with some other answers :

xcode-ios-project-only-shows-my-mac-64-bit-but-not-simulator-or-device

Friday, 1 February 2013

How To change day like calendar's next prev button..


#pragma mark view calnder Next Prev

-(IBAction)btnRigth_Clicked:(id)sender{
    NSLog(@"\n Right Button Clicked");
    [self NextDate:lblTitleDate.text];
}

-(IBAction)btnLeft_Clicked:(id)sender{
    NSLog(@"\n Left Button Clicked");
    [self PrevDate:lblTitleDate.text];
}

-(void)NextDate:(NSString *)strDate{
    
    NSDate *selectedDate = [[NSDate alloc]init];
    selectedDate = [self convertStringToDate:strDate];
    
    // start by retrieving day, weekday, month and year components for yourDate
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *todayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:selectedDate];
    NSInteger theDay = [todayComponents day];
    NSInteger theMonth = [todayComponents month];
    NSInteger theYear = [todayComponents year];
    
    // now build a NSDate object for yourDate using these components
    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setDay:theDay]; 
    [components setMonth:theMonth]; 
    [components setYear:theYear];
    NSDate *thisDate = [gregorian dateFromComponents:components];
    [components release];
    
    // now build a NSDate object for the next day
    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
    [offsetComponents setDay:1];
    NSDate *nextDate = [gregorian dateByAddingComponents:offsetComponents toDate:thisDate options:0];
    [offsetComponents release];
    [gregorian release];
    lblTitleDate.text = [self convertDateToString:nextDate];
}

-(void)PrevDate:(NSString *)strDate{
    
    NSDate *selectedDate = [[NSDate alloc]init];
    selectedDate = [self convertStringToDate:strDate];
    // start by retrieving day, weekday, month and year components for yourDate
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *todayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:selectedDate];
    NSInteger theDay = [todayComponents day];
    NSInteger theMonth = [todayComponents month];
    NSInteger theYear = [todayComponents year];
    
    // now build a NSDate object for yourDate using these components
    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setDay:theDay]; 
    [components setMonth:theMonth]; 
    [components setYear:theYear];
    NSDate *thisDate = [gregorian dateFromComponents:components];
    [components release];
    
    // now build a NSDate object for the next day
    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
    [offsetComponents setDay:-1];
    NSDate *prevDate = [gregorian dateByAddingComponents:offsetComponents toDate:thisDate options:0];
    [offsetComponents release];
    [gregorian release];
    lblTitleDate.text = [self convertDateToString:prevDate];
}

-(NSDate *)convertStringToDate:(NSString *) date {
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
    NSDate *nowDate = [[[NSDate alloc] init] autorelease];
    [formatter setDateFormat:@"EEEE, dd MMM yyyy"];// set format here which format in string date
    date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""];
    nowDate = [formatter dateFromString:date];
    // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate);
    return nowDate;
}

-(NSString *)convertDateToString:(NSDate *) date {
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
    NSString *nowDate = [[[NSString alloc] init] autorelease];
    [formatter setDateFormat:@"EEEE, dd MMM yyyy"];// set format here which format in string date
    
    nowDate = [formatter stringFromDate:date];
    // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate);
    return nowDate;
}

Saturday, 12 January 2013

Set Dyanamic Color or change the color of UIImage..

-(UIImage *)imageNamed:(NSString *)name withColor:(UIColor *)color{

    
    // load the image
//    NSString *name = @"badge.png";
    UIImage *img = [UIImage imageNamed:name];
    
    // begin a new image context, to draw our colored image onto
    UIGraphicsBeginImageContext(img.size);
    
    // get a reference to that context we created
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    // set the fill color
    [color setFill];
    
    // translate/flip the graphics context (for transforming from CG* coords to UI* coords
    CGContextTranslateCTM(context, 0, img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    
    // set the blend mode to color burn, and the original image
    CGContextSetBlendMode(context, kCGBlendModeColorBurn);
    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
    CGContextDrawImage(context, rect, img.CGImage);
    
    // set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
    CGContextClipToMask(context, rect, img.CGImage);
    CGContextAddRect(context, rect);
    CGContextDrawPath(context,kCGPathFill);
    
    // generate a new UIImage from the graphics context we drew onto
    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    //return the color-burned image
    return coloredImg;
}

use this like bellow...

    yourImageView.image = [self imageNamed:@"yourImageName" withColor:[UIColor orangeColor]];


See this link also...
and other link