Showing posts from June, 2010

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:

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:
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

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: 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.

MFMessageComposeViewController Sample Code (OS 4.0 only)

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


@interface SMS2ViewController : UIViewController {
UILabel *message;

@property (nonatomic, retain) UILabel *message;



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 {