Archive for the ‘Programming/iPhone’ Category.
[iPhone APP] WebNote 1.0 , Simple Safari , Memo , Mail Integrated app.
![]() |
Integrated Safari , Memo , Mail in one app. , You can use this simple app to reference web pages and make a note , then mail the note to you or mail to any email address, you can customize web startup location and search engine location in this app to suit your need. |
Continue reading ‘[iPhone APP] WebNote 1.0 , Simple Safari , Memo , Mail Integrated app.’ »
[iPhone] 做一個像 FB / twitter 下拉即更新的 sample code
http://www.waterworld.com.hk/zh-hant/blog/pull-down-refresh-table-view
[iPhone dev] 今天看到一個精巧的設計 / tableview / iPhone design pattern
首先, 可以這樣定義 , 定義出有 3 個 section , 在那個 enum Sections array 中, 第一個 item 就讓它的 value = 0 , 那麼最後一個item : NUM_SECTIONS 的 value自然就是這個 array 的 item 數, 就這樣精簡漂亮!!讚嘆! code 寫這樣就非常清楚易懂, 也好 maintain.
再依此定義出 每個 section 的 rows …..

—-
在 numberOfRowsInSection 中, 直接來個 switch(section) 用 case name 的方式 ,直接 return 該 section 有多少 rows 數值回去…, 若無法 mapping 到的 section 就是用 default return 0;

—
在 cellForRowAtIndexPath 中 , 要 show 出該 section 的 該 row 內容, 也是用 switch case mapping 的方式 , 把正確的內容回傳…

—
點選 row 時的處理, 也是同樣的作法…

—
推薦 iPhone & iPad App 開發參考書 / dev books
![]() |
iPhone.and.iPad.Apps.for.Absolute.Beginners(Apress.2010-05) |
我的第一隻 iPhone 程式 – HelloMap !
這隻程式會展現一個地圖, 並以目前定位的座標為中心點, 及一個按鈕,按下按鈕會把座標及UDID傳送到 server , 由 server 端的程式記錄下來, 並且 server 端亂數送出一個水果名回傳給 iPhone client 端, iPhone client 端再把這水果名 show 在 iPhone screen上.
底下是片斷程式碼:
FirstViewController.h :
#import#import #import @interface FirstViewController : UIViewController { IBOutlet MKMapView *mapView; CLLocationManager *locationManager; CLLocation *currentLocation; } - (IBAction) updateLocation; @end
FirstViewController.m :
- (void)viewDidLoad {
[super viewDidLoad];
if (locationManager==nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
}
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"Location : %.6f , %.6f", newLocation.coordinate.latitude , newLocation.coordinate.longitude );
MKCoordinateRegion region = [mapView region];
region.center = newLocation.coordinate;
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.01;
region.span = span;
[mapView setRegion:region animated:TRUE];
//
if ( currentLocation != nil) {
[currentLocation release];
currentLocation = nil;
}
currentLocation = [newLocation copy];
}
- (IBAction) updateLocation {
if(currentLocation==nil)
return;
UIDevice *device=[[UIDevice alloc] init];
NSString *URLString=[[NSString alloc] initWithFormat:@"http://z.monster.tw/save_location.php?lat=%.6f&lng=%.6f&id=%@"
,currentLocation.coordinate.latitude
,currentLocation.coordinate.longitude
,device.uniqueIdentifier];
[device release];
NSLog(@"%@",URLString);
// Send Request
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:20.0];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
// Display AlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:returnString message:@"Thanks!"
delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil];
[alert show];
[alert release];
[returnString release];
}


