Archive for June, 2010

[iOS] use file from resource folder

Thursday, June 24th, 2010

You should add file to resource folder.

	NSString *path = [[NSBundle mainBundle] pathForResource:@"myxml" ofType:@"xml"];
	NSString *xmlstr = [[NSString alloc] initWithContentsOfFile:path];

[iOS] NSData to NSString or UIImage

Thursday, June 24th, 2010

NSData to NSString

NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSData to UIImage

UIimage *img = [[UIImage alloc] initWithData:data];

refer to
>> エンコードを指定して、NSData <-> NSString を変換する
>> UIImageとNSDataの相互変換

[iOS] NSTimer

Wednesday, June 23rd, 2010

How to use the NSTimer.

	//start timer
	[NSTimer scheduledTimerWithTimeInterval:1.0f 
	if (currentTimer != nil) {
		[currentTimer invalidate]; //stop timer
		currentTimer = nil;
		[currentTimer release];
		count = 0;

-(void)timerHandler:(NSTimer *) timer
	currentTimer = timer;
	count += 1;
	NSLog(@"%d", count);
	label.text = [NSString stringWithFormat:@"count is %d", count];

I don’t understand how to use @selecter.
But I understand that it needs function name with colon (ex foo:).

[iOS] Affine transform, drag and drop

Sunday, June 20th, 2010

I have could do this !



@interface AffineTest2ViewController : UIViewController {
	UIImageView *img;
	UIImageView *circle;
	CGRect initImgRect;
	CGPoint startPt;
	CGAffineTransform startTrans;
@property (nonatomic, retain) IBOutlet UIImageView *img;
@property (nonatomic, retain) IBOutlet UIImageView *circle;


//  AffineTest2ViewController.m
//  AffineTest2
//  Created by kinkuma on 10/06/20.
//  Copyright __MyCompanyName__ 2010. All rights reserved.

#import "AffineTest2ViewController.h"

@implementation AffineTest2ViewController
@synthesize img;
@synthesize circle;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	initImgRect = img.frame;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
	UITouch *touch = [touches anyObject];
	CGPoint pt = [touch locationInView:self.view];
	startPt = [self.img convertPoint:pt fromView:self.view];

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
	UITouch *touch = [touches anyObject];
	CGPoint current = [touch locationInView:self.view];
	CGPoint pt = [self.img convertPoint:current fromView:self.view];
	CGAffineTransform trans = img.transform;
	trans = CGAffineTransformTranslate(trans, pt.x - startPt.x, pt.y - startPt.y);
	img.transform = trans;

- (IBAction)rotateImg
	CGAffineTransform current = img.transform;
	CGAffineTransform trans = CGAffineTransformRotate(current, M_PI * 30 / 180);
	img.transform = trans;

- (IBAction)moveRight

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	// Release any cached data, images, etc that aren't in use.

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;

- (void)dealloc {
    [super dealloc];


[iOS] Check the Class Identify when UITabBarController error

Friday, June 11th, 2010

Today, I used UITabBarController.

I laid the UIView and put the UIButton on it.
And connected to the UIViewController’s IBAction.
I tried to Build and Go, but it was not worked with Error.

I look for that solution.
And I understood.

In InterfaceBuilder, firstcheck is NIB Name. (View)

and this is important that you check the Class Identify. (Controller)

[iOS] @property

Wednesday, June 9th, 2010



@interface MyProperty : NSObject {
	int x;
	NSString *name;
@property int x;
@property (retain) NSString *name;



#import "MyProperty.h"

@implementation MyProperty

@synthesize x;
@synthesize name;



#import "MyProperty.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    MyProperty *myppt = [[MyProperty alloc] init];
	NSLog(@"x is %d, name is %@", myppt.x,;
	myppt.x = 19; = @"bar";
	NSLog(@"x is %d, name is %@", myppt.x,;
	[myppt release];
    [pool drain];
    return 0;