2009年9月9日 星期三
Quartz introduction
2009年9月5日 星期六
install ipa
thread & lock
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
create new thread to do something
- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg;
sleep
[NSThread sleepForTimeInterval:0.5]
lock:
ex:
NSLock *testLock = [[NSLock alloc] init];
[testLock lock];
[testLock unlock];
[testLock release];
2009年9月3日 星期四
ipod touch 破解方法
2009年8月27日 星期四
UIViewController
UIButton
2009年8月26日 星期三
core animation
shorter word to access app delegate
#define AppDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate]
then use AppDelegate in the code
do something in the future
1. execute function in the future
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;
ex: [self performSelector:@selector(sing:) withObject:nil afterDelay:1.4];
2. use timer
(NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
2009年8月25日 星期二
2009年8月18日 星期二
modify view class for view controller
2009年8月13日 星期四
2009年8月12日 星期三
trigger iphone vibrate
2009年8月5日 星期三
2009年8月4日 星期二
get current time
2009年8月1日 星期六
animation delegate
2009年7月30日 星期四
2009年7月5日 星期日
2009年6月14日 星期日
combine UITabBarController & UINavigationController
2009年6月10日 星期三
Game kit
2009年6月4日 星期四
sqlite
2009年6月3日 星期三
dial phone number
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://+886223699148"]];
call 02-23699148
2009年5月26日 星期二
2009年5月20日 星期三
2009年5月16日 星期六
UITableView
NSIndexPath *selection = [self.tableView indexPathForSelectedRow];
if(selection)
{
[self.tableView deselectRowAtIndexPath:selection animated:YES];
}
[self.tableView reloadData];
2009年4月21日 星期二
2009年4月14日 星期二
2009年4月8日 星期三
life cycle of iphone app
2009年4月4日 星期六
create view controller
2009年4月3日 星期五
add view method
2009年4月2日 星期四
find memory leak with clang
- Make sure the project default settings are “debug” and “simulator”
- Close Xcode
- open a terminal window and “cd” to the project directory
- run rm -rf /tmp/scan-build*
- run rm -rf build/;scan-build --view xcodebuild
- Open Xcode and fix errors
2009年3月28日 星期六
install app on iphone
2009年3月27日 星期五
add photo in iphone simulator
2009年3月26日 星期四
iphone error message
[Session started at 2009-03-27 00:21:00 +0800.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
warning: Unable to read symbols for "/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics" (file not found).
warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
answer: this is usually memory problem, remember to retain & release
use picker
file's owner
2009年3月24日 星期二
tab bar app
2009年3月22日 星期日
create multiview app
2009年3月21日 星期六
remove app in iphone simulator
2009年3月20日 星期五
delegate in iphone
file's owner in interface builder
2009年3月19日 星期四
2009年3月8日 星期日
international call software
直撥國際電話須先撥所在地「國際冠碼」,再撥受話方「國碼」、「區域號碼」及「電話號碼」,區域號碼前之0不須撥。舉例如下:
1.從國外撥回台灣:該國國際冠碼(詳如下表)+台灣國碼 (886)+區域號碼(去0)+用戶電話號碼。
★如從中國撥回台北市 00+886+2+XXXX-XXXX
★撥台灣行動電話時 00+886+937-XXX-XXX
註:若以手機撥打台灣的電話,只要在國碼886之前以「+」替代該國國際冠碼即可。
2.從台灣撥往國外:台灣國際冠碼(002)+該國國碼+區域號碼(去0)+用戶電話號碼。
★如從台灣撥往中國北京 002+86+10+XXXX-XXXX
★撥中國北京行動電話 002+86+行動電話號碼
註:國際間的行動電話第一碼不一定為0,如是0的話也要去掉。
要注意的是,國碼不會變,但有些國家冠碼卻不只一個,如台灣除熟知的「002」外,還有「009、006」等,差別在於費率。
2009年2月25日 星期三
2009年2月18日 星期三
category
2009年2月16日 星期一
method calling
ex:
[ c setName: @"peter" age: 3];
two parameters, first is @"peter", second is 3
age: is name for second argument
advantage: readability
2009年2月10日 星期二
xcode
2009年2月9日 星期一
memory management
when object is created via alloc, new, or copy, the object's retain count is set to 1
use retain to increase retain count
use release to decrease retain count
use retainCount to know object's retain count
retain count in accessor:
ex:
class Boy has an instance variable for book
- (void) setBook: (Book*) newBook
{
[newBook retain];
[book release];
book = newBook;
}
note:
when boy object is deallocated, it will release book object's retain count for retain count it increase in setBook
autorelease:
when object is sent autorelease message, it is put in autorelease pool
when the pool is destroyed, all objects in pool are sent a release message
ex:
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
Book *book = [[Book alloc] init];
[book autorelease];
[pool release];
note:
1. for iphone, avoid using autorelease and the functions that give autoreleased object
2. the same object can be autoreleased many times
drain:
the drain method for pool empties out the pool without destroying the pool
rule for reatin count:
1. when getting object from new, alloc, or copy, you must send the object release or autorelease when you are done with it
2. when getting object via other methods, assume it has a retain count of 1 and it has been autoreleased . If you want to hold object for some time, just retain it and release it when you are done
ex:
in an event loop, a pool is created before handling event. And the pool is destroyed after handling event. Hence, the object created during the event loop must retain if you want to keep it
3. if your retain an object, you need to release or autorelease it
garbage collection:
not support iphone
enable gc:
Build -> objective-c garbage collection
dynamic and late binding
the object will find speak method automatically
ex:
Shape *a = [Circle new];
[a draw];
In java, you have to change object's type to People to call People's method
ex:
Shape a = new Circle();
(Circle)a.draw(); // Circle's draw method is called
create object ,new, alloc, init, dealloc
ex:
id c = [Circle new];
class:interface, implementation, inheritance, accessor, @property, dot
@interface Student : NSObject
{
int age;
}
- (void) setAge: (int) age;
- (void) speak;
@end
note:
1.if a method has argument, its name has a colon
2. inheritance:
a. use : , NSObject is super class of Student
b. not support multiple inheritance
3. isa:
instance varabile of NSObject, a pointer to the object's class
4: super
call parent class's method definition
ex:
[super speak];
@implementation Student
- (void) setAge: (int) a
{
age = a;
}
- (void) speak
{
NSLog(@"speak");
}
@end
note: if parameter uses the same name as instance variable,
new accessor method: @property & @synthesize
create accessor for you
ex:
@interface People {
int age;
}
@property int age;
@end
@implementation People
@synthesize age;
@end
you can use dot to access instance variable
ex:
peter.age
special keyword in objective-c, id, BOOL, nil, @class
a generic type to refer to any kind of object
ex:
id c = [Circle new];
BOOL:
type for boolean
YES(1) or NO(0)
2009年2月4日 星期三
hello world example, NSLog, NSString
2. Hello.m
#import
int main (int argc, const char *argv[])
{
NSLog (@"Hello, Objective- C!");
return (0);
} // main
3. build and go
click build and go button or com+ R
selelct Console from Run or cmd+shift+R
note:
1. import:
like include in C, but guarantees that a header file will be
included only once, no matter how many times the #import
directive is actually seen for
that file.
2. foundation framework:
handle features found in the layers beneath UI, such as
data structure and communication mechanisms
location:
/System/Library/Frameworks/Foundation.framework/Headers/
3. master header file
Each framework has a master header file that includes all the
framework’s individual header files. By using #import on the master header file,
you have access to all the framework’s features
4. NSLog
like printf, but also print date, time , and append newline
%@:
to print object, the object's description method defines what to print
ex:
5. NSString
begin with @, such as @"hello"
NSString's advantage:
(1) tell you length
(2)compare with another
(3)convert to interger or floating point