Posts

Showing posts from 2010

Great advanced iPhone tutorials

http://www.raywenderlich.com/tutorials
awesome source

Some CG Functions
http://blogs.oreilly.com/iphone/2008/12/useful-core-graphics-functions.html

Objective C Comment Tags

Hi
While writing a software one has to work across multiple files and its easy to forget those mental notes we make to revisit certain parts of the code. Objective C and Xcode provide some niftly tags to mark these areas in the code. The Tags are:

1) TODO
Syntax:
// TODO: add function call

2) FIXME
Syntax:
// FIXME: remove view and add image

3) ???
Syntax
// ???: How does this work?

4) !!!
Syntax
// !!!: to be verified

Via: http://iphonedevelopertips.com/xcode/xcode-fixme-and-todo.html

Base64 encoding in objective c

this is what worked for me. May be a lot more later.
reference: http://stackoverflow.com/questions/392464/any-base64-library-on-iphone-sdk
//
// encode64.m
// encode64vr1
//
// Created by Shubham Goel on 11/11/10.
// Copyright 2010 What an App.com. All rights reserved.
//

#import "encode64.h"


@implementation encode64

static char base64EncodingTable[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'…

Website Design Time Saving Tools

Add background to table view

Add a view with the image to the window or the view controlling the table view. In my case it was a navigation view. UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];
[window addSubview:backgroundView];
[backgroundView release];
Code from: http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/

Changing the accessory view icon

Changing the stupid accessory icon is small exercise if you know precisely the right steps.

Create the icon and change the accessory view to the icon view
UIButton* pencil = [UIButton buttonWithType:UIButtonTypeCustom];
[pencil setImage:[UIImage imageNamed:@"icon-pencil.gif"] forState:UIControlStateNormal];
pencil.frame = CGRectMake(0, 0, 15, 15);
pencil.userInteractionEnabled = YES;
[pencil addTarget:self action:@selector(didTapEditButton:) forControlEvents:UIControlEventTouchDown];
cell.accessoryView = pencil;
Code from:
http://osmorphis.blogspot.com/2009/07/changing-accessory-view.html
as a custom controller has been called it need to know the IndexPath. For that use: - (void)checkButtonTapped:(id)sender event:(id)event { NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; if (indexPath != nil) { [self tableView:…

Using custom delegates in Objective-C

via: http://jonsterling.github.com/2009/08/01/using-custom-delegates-in-objective-c.html
On Stack Overflow there has been some interest in how to use the Delegate design pattern in Objective-C. Of course, the first step in any search should be to read Apple's documentation, but many people seem not to want to read the whole thing. Trust me, folks, it is worth it. But Apple's documentation on creating delegates doesn't use protocols, which are such an amazing and useful part of the Objective-C language.That being said, I'd like to give a short demonstration of how to create a class with a delegate. For the purposes of this tutorial, we'll call our class JSTutorial. The interface to JSTutorial starts out as the following:@interfaceJSTutorial:NSObject{ NSString*title; NSString*body; }

Change wallpaper programatically

Via:http://iphonedevwiki.net/index.php/UIImage Undocumented APIs to set and get the iPhone wallpaper programmatically. I hope these are legalized soon. There would be no end to the kind of things that can be done with them+defaultDesktopImageSignature+(UIImage*)defaultDesktopImage;Available in2.0 –Return the user's lock screen image.+setDesktopImageData:Signature+(void)setDesktopImageData:(NSData*)jpegData;Available in2.0 –Replace the user's lock screen image by the given JPEG data.

What is ASIHTTPRequest?

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier. It is written in Objective-C and works in both Mac OS X and iPhone applications.
It is suitable performing basic HTTP requests and interacting with REST-based services (GET / POST / PUT / DELETE). The included ASIFormDataRequest subclass makes it easy to submit POST data and files using multipart/form-data.
http://allseeing-i.com/ASIHTTPRequest/

MFMessageComposeViewController Sample Code (OS 4.0 only)

Image
Via: http://iphonesdkdev.blogspot.com/2010/04/mfmessagecomposeviewcontroller-sample.html
Start a new View-based Application Project called SMS2
and have to add the MessageUI framework to the project

Modify SMS2ViewController.h

// SMS2ViewController.h
// SMS2

#import
#import
#import

@interface SMS2ViewController : UIViewController {
UILabel *message;
}

@property (nonatomic, retain) UILabel *message;

-(void)displayComposerSheet;

@end


and in SMS2ViewController.m


// SMS2ViewController.m
// SMS2

#import "SMS2ViewController.h"

@implementation SMS2ViewController
@synthesize message;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/


// Implement loadView to create a view hierarchy programmatically, without using a nib.
/*
- (void)loadView {

}
*…

Shake Gesture

If you are planning to use the shake gesture to trigger an event add the following code to your UIViewController
-(