1. "Work with timer NSTimer"

    Mon 11 May 2009

    //setup timer somewhere in the code

    [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(onTimerEvent:)userInfo:nil repeats:NO];

     

    - (void)onTimerEvent:(id)userInfo{

            //Your code when timer fires

    }

    read more
  2. "Do something when application terminated"

    Mon 11 May 2009

    //in mainAppDelegate.m

     - (void)applicationDidFinishLaunching:(UIApplication *)application {

    //

    //init code

    //

      atexit(applicationWillTerminate);

     

    void applicationWillTerminate(){

    //some stuff

     

     

    //in mainAppDelegate.h

    @interface mainAppDelegate : NSObject <UIApplicationDelegate> {

    //.....

    }

    void applicationWillTerminate(); 

    read more
  3. "Select image from library"

    Mon 11 May 2009

    - (void)addAction:(id)sender{

    // Set up the image picker controller and add it to the view

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

    imagePickerController.delegate = self;

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePickerController animated:YES];

    }

     

     

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

    {

    [picker dismissModalViewControllerAnimated:YES];

    //Save images in DB 

    MInsuranceImage ...

    read more
  4. "Parse XML using iPhone SDK"

    Mon 11 May 2009

    //

    //  XMLReader.h

     

    #import <UIKit/UIKit.h>

     

    @class MSearchItem;

     

    @interface XMLReader : NSObject {

    @private

    MSearchItem *searchItemObj;

    NSMutableString *_contentOfCurrentUserSession;

    NSMutableArray *searchList;

    }

     

    @property (nonatomic, retain) MSearchItem *searchItemObj;

    @property (nonatomic, retain) NSMutableString *contentOfCurrentUserSession;

    @property (nonatomic, retain) NSMutableArray *searchList;

     

    -(void)parseXMLFileAtURL:(NSURL *)URL parseXMLFile:(NSData *)fileData parseError:(NSError **)error;

     

    @end

     
     

    //

    //  XMLReader.m

     

    #import "XMLReader.h"

    #import ...

    read more
  5. "Empty Database.m/h template for sqllite3"

    Mon 11 May 2009

    //

    //  Database.h


    #import <Foundation/Foundation.h>

    #import <sqlite3.h>


    @interface Database : NSObject {

    sqlite3 *database;

    NSString *dbPath;

    }

     

    + (Database *)sharedDatabase;

    - (void)createEditableCopyOfDatabaseIfNeeded;

    - (void) openDb;

    @end

     

    //-----------------------------------------------------------------------------------------------------

    //  Database.m


    #import "Database.h"


    @implementation Database

     

    static Database *_sharedDatabase;

     

    BOOL dbOpen = NO;

     

    + (Database *)sharedDatabase

    {

    if (!_sharedDatabase) {

    _sharedDatabase = [[Database alloc] init];

    }

    return _sharedDatabase;

    }

    // Creates a writable copy ...

    read more
  6. "Create UIButton in runtime"

    Mon 11 May 2009

    UIButton *registerButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

    registerButton.frame = CGRectMake(80.0, 170, 150.0, 30.0);

    [registerButton setTitle:@"From Contacts" forState:UIControlStateNormal];

    [registerButton addTarget:self action:@selector(fromContactsAction:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:registerButton];

    read more
  7. "Animate fade in/out"

    Mon 11 May 2009

     

    IN *.m file  

    ------------------------------ 

    #pragma mark ANIMATION

    //-------fade in

    -(void)animateFadingIn{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationDelegate:self];

    //set transformation

    [UIView commitAnimations];

    }

     

    //-------fade out

    - (void)animateFadingOut{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationDidStopSelector:@selector(fadeAnimationDidStop:finished:context:)];

    [UIView setAnimationDelegate:self];

    //set transformation ...

    read more
  8. "Get information from iPhone address book (only with emails)"

    Mon 11 May 2009

     //Also you need to include AddressBook.framework

    #import <AddressBook/AddressBook.h>

    #import <AddressBook/ABAddressBook.h>

    #import <AddressBook/ABPerson.h>

     

    [contactList removeAllObjects];

    // open the default address book. 

    ABAddressBookRef m_addressbook = ABAddressBookCreate();

    if (!m_addressbook) {

        NSLog(@"opening address book");

    }

    // can be cast to NSArray, toll-free

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);

    CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

    // CFStrings ...

    read more
  9. "Transformation in OpenGL (GL_MODELVIEW / GL_TEXTURE)"

    Mon 11 May 2009

    glPushMatrix();

    {

    // - in MODEL MODE 

     

    //translate

    glTranslatef(0.0, 0.0, 0.0);

    //scale 

    glScalef(1.0, 1.0, 1.0);

    //rotate 

    glRotatef(0.0, 0.0, 0.0, 0.0);

    glMatrixMode( GL_TEXTURE );

    glPushMatrix();

    {

    // - in TEXTURE MODE

    //translate

    glTranslatef(0.0, 0.0, 0.0);

    //scale 

    glScalef(1.0, 1.0 ...

    read more
  10. "Get application options"

    Mon 11 May 2009

    BOOL isSomething = [[NSUserDefaults standardUserDefaults] boolForKey:@"enabled_something"];

    NSInteger someIntValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"some_integer"];


    read more

« Page 10 / 13 »