Flipkart Search

Search This Blog

Tuesday, July 6, 2010

Opting Out of Background Execution in iPhone OS 4.0

If you do not want your application to remain in the background when it is quit, you can explicitly opt out of the background execution model by adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES. When an application opts out, it cycles between the not running, inactive, and active states and never enters the background or suspended states. When the user taps the Home button to quit the application, the applicationWillTerminate: method of the application delegate is called and the application has approximately five seconds to clean up and exit before it is terminated and moved back to the not running state.
Opting out of background execution may be preferable for certain types of applications. Specifically, if coding for the background may require adding significant complexity to your application, terminating the application may be a simpler solution. Also, if your application consumes a large amount of memory, the system might need to terminate your application quickly anyway to make room for other applications. Thus, opting to terminate, instead of switch to the background, might yield the same results and save you development time and effort.

Tuesday, June 22, 2010

Customize the default UISlider in iPhone

here is a simple way to customize the UISlider images

UIImage *stetchLeftTrack = [[UIImage imageNamed:@"left-slide.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    UIImage *stetchRightTrack = [[UIImage imageNamed:@"right-slide.png"]
                                 stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    [sldDistanceFilter setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
    [sldDistanceFilter setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [sldDistanceFilter setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];

You just need to replace the image names according to your suite.

Wednesday, May 12, 2010

Limit Characters in UITextField

Here is a simple delegate method to limit the characters in UITextfield :-

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
        NSUInteger newLength = [textField.text length] + [string length] - range.length;
        return (newLength > 8) ? NO : YES;
}

Saturday, April 17, 2010

Difference b/w NSArray and NSMutableArray

NSMutableArray (and all other classes with Mutable
in the name) can be modified. So, if you create a plain NSArray,
you cannot change its contents later (without recreating it). But if
you create an NSMutableArray, you can change it.

Friday, April 16, 2010

Difference between signed and unsigend data types

Signed Data Type - a signed data type is one that can hold both positive or negative values, i.e. -1 or +456. A 32 bit signed integer can hold the range -2147483648 to 2147483647

Unsigned Data Type - Unsigned data types can only hold positive values.
An unsigned 32 bit integer for instance can hold the range 0 to 4294967296

Tuesday, April 13, 2010

The most annoying Xcode error ever: The Info.plist for application at (null) specifies a CFBundleExecutable of (null), which does not exist.

If you're developing an iPhone application in XCode and getting the
error:
“The Info.plist for application at (null)
specifies a CFBundleExecutable of (null), which does not exist.”
here's
how to fix it:

In Xcode, choose "Executables" from the project
hierarchy. Click your project executable then press Command-I. Choose
the General tab and set the working directory to "Build Products
directory".

This fixed the problem. The advisory from Apple did
not help much, but did mention the Build Products directory. Under SDK
release notes for iPhone OS 3.1, XCode/Developer Tools
:

"Changing
an iPhone Executable's working directory from “Build Products
directory” may cause the application not to install properly with the
error message “The Info.plist for application at (null) specifies a
CFBundleExecutable of (null), which does not exist.”"
Hope
this saves you a little time. It frustrated me for a while.

Thursday, April 8, 2010

Get list of all available fonts with family names in iPhone

Here is the piece of code to get list of all available fonts in your iPhone. This will print the list in gdb          


NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
            NSArray *fontNames;
            NSInteger indFamily, indFont;
   
            for (indFamily=0; indFamily<[familyNames count]; ++indFamily){
               
                NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
               
                fontNames = [[NSArray alloc] initWithArray:
                             [UIFont fontNamesForFamilyName:
                              [familyNames objectAtIndex:indFamily]]];
                for (indFont=0; indFont<[fontNames count]; ++indFont){
                   
                    NSLog(@"Font name: %@", [fontNames objectAtIndex:indFont]);
                }
               
                [fontNames release];
            }
   
            [familyNames release];

Thursday, November 26, 2009

Funny UIPickerView Animation

//Take a NSTimer object and a integer variable in your header file like this

   NSTimer *timer;
   int ComponentNumber;

//Put this line into your viewDidLoad

    ComponentNumber=0;
    timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(ChangeComponentNumber) userInfo:nil repeats:YES];


-(void)ChangeComponentNumber
{
    if(ComponentNumber>8)
    {
        [timer invalidate];
        return;
    }
    else if(ComponentNumber==4)
    {
        ComponentNumber=ComponentNumber+1;
        [self performSelector:@selector(HidePickerComponents) withObject:nil afterDelay:0.0];
    }
    else
    {       
        [self performSelector:@selector(HidePickerComponents) withObject:nil afterDelay:0.0];
    }
}
-(void)HidePickerComponents
{   
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];   
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:AlarmSoundPicker cache:YES];
    [(UIView*)[[AlarmSoundPicker subviews] objectAtIndex:ComponentNumber] setHidden:YES];   
    [UIView commitAnimations];   
    ComponentNumber=ComponentNumber+1;
   
}

Wednesday, November 11, 2009

Convert All TimeZones To UTC TimeZone format

//*******Convert Any TimeZone To UTC*******//

-(NSString *)getUTCFormateDate:(NSDate *)localDate
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    [dateFormatter setTimeZone:timeZone];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString = [dateFormatter stringFromDate:localDate];
    return dateString;
}

Saturday, November 7, 2009

Change navigation bar color in iphone sdk

here is how ou change your navigation bar color.

navigationController.navigationBar.tintColor=[UIColor colorWithRed:42/256.0 green:60/256.0 blue:80/256.0 alpha:1.0];

just replace the (42,60,80) to your desired RGB Value.