Wednesday, 28 May 2014

Convert date in MM/dd/yyyy format

NSString *str = @"2012-10-30"; /// here this is your date with format yyyy-MM-dd

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; // here we create NSDateFormatter object for change the Format of date..
[dateFormatter setDateFormat:@"yyyy-MM-dd"]; //// here set format of date which is in your output date (means above str with format)

NSDate *date = [dateFormatter dateFromString: str]; // here you can fetch date from string with define format

dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];// here set format which you want...

NSString *convertedString = [dateFormatter stringFromDate:date]; here convert date in NSString
NSLog(@"Converted String : %@",convertedString);

Wednesday, 21 May 2014

Sorting an NSArray in ascending order

 NSArray *sorted = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            if ([obj1 intValue] < [obj2 intValue]) return NSOrderedAscending;
            else return NSOrderedDescending;
        }];
NSLog(@"sorted ~~~~~~~ %@",sorted);

(OR)

NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"self" ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [array_value_name sortedArrayUsingDescriptors:sortDescriptors];

Tuesday, 6 May 2014

Uitableviewcell disable the uibutton for editing time

      for (int row = 0, rowCount = [myTable numberOfRowsInSection:0]; row < rowCount; ++row) {
            
            UITableViewCell *cell = [myTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];
            UIButton *forwordbtn1 = (UIButton *)[cell viewWithTag:410];
            forwordbtn1.enabled = NO;
        }


Here 410 is uitableviewcell button tag value.

resize UISwitch button

mySwitch.transform = CGAffineTransformMakeScale(0.75, 0.75);