Copy_N_Paste
parsing HTML on the iPhone
[上午 10:17:04] _RTN 神奇傑克: object-c的html parser 這裡有解答 http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone
libxml2.2 comes in the SDK, and libxml/HTMLparser.h claims the following:
This module implements an HTML 4.0 non-verifying parser with API compatible with the XML parser ones. It should be able to parse "real world" HTML, even if severely broken from a specification point of view.
[MEMO/TIPS] iPhone class / method / instance naming convention
class : 大寫開頭
method / instance : 小寫
Property List / SQLite 寫法 sample
類似 printf 的寫法
NSString *debugMsg = [NSString stringWithFormat:@"Process %d", 1];
取亂數
定義: #define RANDOM_SEED() srandom(time(NULL)) #define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__))) // --- 這樣用 NSLog(@"%d" , RANDOM_INT(0,9) );
取 unixtime :
NSDate *past = [NSDate date]; NSTimeInterval oldTime = [past timeIntervalSinceDate:[NSDate dateWithNaturalLanguageString:@"01/01/1970"]]; NSString *unixTime = [[NSString alloc] initWithFormat:@"%0.0f", oldTime]; NSLog(@"%@" , unixTime);
印出 debug message / popup alert 的寫法:
// --- -(void) printdebug:(id)msg { NSLog(@"%@", msg); } // --- -(void) displayAlertMessage:(id)msg { // Display AlertView UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"___Alert___" message:msg delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil]; [alert show]; [alert release]; }
Objective-C 奇怪的 null detect!
if ( (NSNull *)[item objectForKey:@"nick"]==[NSNull null] ) { // FOR GUEST DATA cell.textLabel.text = @"Guest"; } else { // FOR MEMBER DATA cell.textLabel.text = [item objectForKey:@"nick"]; }
ASYNC network 寫法:
http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/
—-
Programming in Objective-C , sample code
這邊有一些 objective-c 的基本認識 , 參考 URL : http://www.otierney.net/objective-c.html.zh-tw.big5
[URL] iPhone programming bookmarks / reference
★ Your First iOS Application
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhone101/Articles/00_Introduction.html
中文 : http://icodeblog.com/category/iphone-programming-tutorials/
★★ iOS Reference Library : http://developer.apple.com/iphone/library/navigation/index.html
iPhone Dev Center : http://developer.apple.com/iphone/index.action
iPhone Human Interface Guidelines : http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html
objective-c 的基本認識 , 參考 URL : http://www.otierney.net/objective-c.html.zh-tw.big5
有趣的 iPad iPhone development video 教學 : http://www.rorylewis.com/docs/02_iPad_iPhone/05_iPhoneTutorials.htm
給初接觸 objective-c 的介紹 : http://maciku.blogspot.com/2009/12/iphone-objective-c.html
包裝好給 iPhone 用的 http 元件/framework – ASIHTTPRequest
http://allseeing-i.com/ASIHTTPRequest/
—-
7/31 iPhone dev 課程 outline :
iPhone spec. / Objective-c intro.
intro. xcode / iPhone 開發限制 / 應用軟體架構 / 記憶體管理
first App. – HelloWorld
程式語法 – simple
Interface Builder基本操作
字串與資料結構 / UI Catalog
second App. – Location base App.
upload to real iPhone – use Apple
★ init , copy , retain 要記得 release memory
★ didReceiveMemoryWarning , viewDidUnload 暫時釋放 memmory
★ IBOutlet 引用到的 InterfaceBuilder 元件建議作 release , 但要注意到不要重覆 release
★ InterfaceBuilder : 事件與程式碼配合 – IBAction , 物件關聯 – IBOutlet , Delegate 指定.
A simple Objective-C Method Declaration and Definition
定義
- (void) sayHello: (NSString*) name;
implementation :
- (void) sayHello: (NSString*) name { NSMutableString *message = [[NSMutableString alloc] initWithString:@"Hello there "]; [message appendString:name]; NSLog(message); [message release]; } //
simple.m 宣告 sayHello method:
#import "Simple.h" @implementation Simple - (void) sayHello: (NSString *) name { NSMutableString *message = [[NSMutableString alloc] initWithString:@"Hello there "]; [message appendString:name]; NSLog(message); [message release]; } @end //
simple.h
#import @interface Simple : NSObject { } -(void) sayHello: (NSString *) name; @end //
main 呼叫 sayHello method:
#import #import "Simple.h" int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Simple * mySimple = [[Simple alloc] init]; [mySimple sayHello:@"James"]; [mySimple release]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } //
iphone / hello world 2 / single rows in the table view
// -- // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } [cell.textLabel setText:@"Hello World!"]; return cell; } // -- // --