網頁

2012年6月29日 星期五

mac標點符號快速鍵

option + command + T ( 開啟mac 設定)

語言為內建注音的話
  • []=「」
  • \=、
  • shift + 1=!
  • shift + , =,
  • shift + . = 。
  • shift + ?=?
  • shift + []=『』
  • shift + ; = :
  • option + ; =;
持續增加

icon composer使用方法

【環境:xCode4.3.2:icon composer】

說明:
上傳過app到itunes connect的人一定有很多的印象,就是各種不同size的圖片,對於photoshop不熟的人來講,根本就是很麻煩,這時候就要抓出xcode內建的功能程式「icon composer」

icon composer可以讓你自己建立自己的ico,快速方便,各種尺寸,你只需要一張你想要放上去的圖。


使用方式很簡單,就是把圖拖上去,我把.psd檔拖上去也行,總之最後輸出的格式就是依照你最後的設定,不管是512x512、57x57.....輕鬆搞定多種size。



As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

numbers小技巧

【環境:iWork9:Numbers】

在空格中輸入換行:option(alt)+return
建立下拉式選單: 如下圖
建立下拉式選單
 

待續補充

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

善用pragma mark等相關功能去制定你的標簽...

【環境:xCode4.3.2 】

說明:

一般在攥寫程式時,程式人員通常都會用//來表示注解,但其實還有其他方式可以去很方便的表達注解方式,並且跳到該行。


如下列範例:
1.線段分類
#pragma mark - 
線段分類


2.線段分類+標題
#pragma mark - test

以test為分類的標題


3.其他:"//TODO:"、"//FIXME:"、"//!!!:"、"//???:"
 
#pragma mark - test

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *btnDownLoad = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btnDownLoad setTitle:@"test" forState:UIControlStateNormal];
    [btnDownLoad addTarget:self action:@selector(testDL) forControlEvents:UIControlEventTouchUpInside];
    btnDownLoad.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:btnDownLoad];
    
 // Do any additional setup after loading the view.
}
//FIXME:fix
- (void) testDL
{
    NSURL *url = [NSURL URLWithString:@"http://funwish.net/jhaoheng/testDL.rtf"];
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0];
    connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    connection = nil;
    
}
//TODO:todo
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    filesize = [NSNumber numberWithUnsignedInteger:[response expectedContentLength]];
}
//???:??????
//!!!:!!!!!!!!!!!!
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)recievedData {
    if (data==nil) {
  data = [[NSMutableData alloc] initWithCapacity:2048];
    }
    [data appendData:recievedData];
    
    //NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[data length]]; //MAGIC
    //float progress = [resourceLength floatValue] / [filesize floatValue];
    //progressLine.progress = progress;
}

其它相關


As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。





額外補充:
#pragma 是xcode因應可攜碼的方式編寫的程序,例如告訴編輯器,你下面的code是屬於asm 或者是small。

compiler看到#pragma時如果後面的定義是它不認得的, 它不會理會; 相反的看得懂得compiler就會去執行它.

進階的使用方法-請參考

2012年6月28日 星期四

Coda2 ...『you will like this download version』

【環境:Coda 2.0.1】



website:Coda 2
Download:file

WHAT'S NEW
Version 2.0.1: 

Improvements:A "Search" filter has been added to the Files tabImproved autocompletion for HTML, CSS, Javascript, and PHPThe path bar is now truncated to your local / remote root pathPort, User, and IdentityFile in ~/.ssh/config are now parsed for SFTP connectionsOption+Return will now open files in the active tab/split via keyboardAdded Japanese localizationAdded a LESS mode. (If you installed a third-party mode, you might wish to delete it.)

Bug Fixes:

Significantly improved stability on Mac OS X 10.6Hopefully improved the reliability of iCloudImproved the reliability of AirPreviewImproved private key reliability for SFTP connectionsWeb preview more reliably catches external CSS changesPHP rendering will no longer break after saving in some circumstancesFixed an issue where the location of the document cannot be determinedFixed an exception when attempting to clone a Git repositoryFixed issues with code foldingNow possible again to add/edit a search URL for a custom bookNo auto-mark for publishing after ejecting siteSave As no longer also saves to FTP in some circumstancesGit push/pull buttons are no longer gone after a commitFixed a Git error when trying to clone a site to a non-existent directoryCheckout to Revision now works more reliably for GitCode validation improved when collapsedImproved nested Javascript syntax coloringNew Tab and New Split subitems now have unique names so shortcuts can be assignedSSH key selector button now shows hidden filesThe connect button in Sharing is now activeClips can no longer lock up when moving them into a groupRight-clicking in icon view no longer clears the selectionJavascript hints now function properlyUsing the keyboard to navigate through tabs now properly scrolls the tabsWorked around mod_sftp server issue where permissions would be set to 000 when openingFixed a situation where named placeholders could not be named properlyThe mysterious iCloud panel is now disabled on Mac OS X 10.8SCM operations now update the publishing queue"Refresh" menu item and keyboard shortcut now works in SQL viewCMD-F now properly focuses filter boxesViewing page source while previewing in iPad/iPhone frames now renders correctlyThe Color pop is now shown for "border-color"Dragging a remote file tab is now more usefulSCM operations when offline no longer create a string of errorsInvisible files now show up in Find Files resultsThe "Port" is now saved properly in SQL site configurationsCustom book images no longer get stretched in the toolbar iconFixed an issue where the Clips editor window could appear far offscreenFixed various crashes, exceptions, and annoyances!



As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

2012年6月27日 星期三

omnigraffle安裝模具( install gstencil )

【環境:Omnigraffle 4.1.2 中文 for mac】
名稱:將下載的Omnigraffle模具gstencil放入Omnigraffle中使用,如圖1
圖1


說明:
omnigraffle是一個可以快速建立模具的工具程式,不管是組織流程圖還是UML。網路上也有很多使用者建立模具供人下載,我想應該很多人遇過跟我一樣的問題,如何將下載過後的gstencil放入omnigraffle中,可以快速的拉出來使用。

像是開發iphone的工作者,一定會遇到,如何表現出流程佈局?當然訪間有很多工具可以使用,因為以前就用omnigraffle,就順勢了找了一下相關的資料,發現也有人製作出相對應的模具,直接抓下來,就可以使用摟。

下載網址:http://graffletopia.com/

至於安裝模組的方式,就土法煉鋼一下摟~~因為目前找不到更好的方法。
1.首先顯示套件內容(圖二)。
2.找到資料夾放置位置(圖三)。在這邊要注意的是,因為我是中文版,所以注意路徑位置為zh_TW.lproj
3.建立自己的檔案名稱,如iphone,將模具(.gstencil)拉進去(圖四)。
這樣就大功告成。
圖二

圖三

圖四
按照流程走應該就沒問題了。

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

2012年6月18日 星期一

Modal View Controller(一)

【環境:xCode4.3.2 , ios5.1 , USE ARC】

說明:基本上,這指的並不是指一般的視圖控制器,而是指一種顯示視圖控制器的方式,當一個視圖控制器,以modal的方式出現時,稱這個視圖控制器是一種modal view controller,這時出現的視圖控制器會暫時中斷目前程式的工作流程,而專注於目前視圖控制器所交辦的工作,modal view controller通常是用來收集使用者的輸入,或者展示某些訊息給使用者。
通常最常看到的就是頁面的切換吧。

  • presentModalViewController: animated:
  • dismissModalViewControllerAnimated:

first畫面
[目前的頁面 presentModalViewController:將要跳轉的頁面 animated:YES];

change 畫面
[self dismissModalViewControllerAnimated:YES];//切換過的畫面,跳回上一層畫面
相關使用方法,請參閱其他資源。

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

視圖控制資源

【環境:xCode4.3.2 , ios5.1 , USE ARC】
說明:
  1. viewWillAppear
  2. viewDidAppear
  3. viewWillDisappear
  4. viewDidDisappear
這四個方法其實是視圖提供的一些狀態更新資訊,當畫面有異動時,他會藉由這四個方法來通知我們,不過不見得所有的程式都需要知道這些更新的狀態。
所以viewWillAppear和viewDidAppear都是適合修改標題的時機。

除了這四種還有
  • viewDidLoad:當試圖完成載入時呼叫,大部份的情況只會被呼叫依次,通常需要額外載入資料都會在這個方法中實作。在前面介紹修改標題的動作移到此處也是相當合適的一個地方。
  • viewDidUnload:當視圖卸載之後呼叫。

視圖除了上述幾種,還包含
-(void) awakeFromNib

當視圖是由xib載入而不是由手動載入時,系統會跳過試圖內建的初始化方式
-(id) initWithFrame:(CGRect)frame;

改由呼叫另一個初始化方法
-(id) initWithCoder:(NSCoder *)decoder
接下來就會呼叫awakeFromNib,因此當我門想要額外對視圖作設定,而這個視圖又剛好是自動由xib檔案載入,awakeFromNib就是一個很適合為視圖進行額外設定的地方。


As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

UITableViewController觀念(一)

【環境:xCode4.3.2 , ios5.1 , USE ARC】
名稱:UITableViewDelegate,UITableViewDataSource
說明:
UIViewController:「視圖控制器」
UITableViewController:「表格視圖控制器」,他的基本就是從UIViewController延伸過來,方便開發者容易使用,而不需額外製作多餘的工作,標準物件導向的觀念。

但基本下還是必須瞭解在UIViewController下,如何建立UITableViewController的觀念,因為大多數的使用者包含我,剛開始都會產生一個疑惑,為什麼有些時候必須引用一些protocols<uitableviewdelegate,uitableviewdatasource>,有些時候又不需要,這基本就在於你的基礎框架是什麼,我理解的觀念是這樣。

假如你今天直接用UITableViewController的話,那ios已經幫我們建立了一些基本的設定,好讓我們不需要去煩惱其他東西,只需要去構想內容該怎麼寫,甚至連一些會用到的"實體方法"都幫我們建立好,但一定會有一天需要在其他的框架下去建立UITableViewController的時候,這時我們就必須在.h的檔案下,增加Protocols,<uitableviewdelegate,uitableviewdatasource>,相關的協定(protocols)請去參閱相關資料。

引用相關協定後,才可以使用ios已經幫我們準備好的功能,包含-(NSInteger)numberOfSectionInTableView:(UITableView*)tableView{}.....等等。
<以下範例>
 
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>

@end 

  • UITableViewDelegate:提供表格視圖用來管理、設定表格區段、標題、頁尾等等所需的資訊,同時亦協助管理表格資料的刪除、修改等工作。
  • UITableViewSource:為表格提供顯示的資料。
額外補充
UITableViewController實作了一個叫做UITableViewDataSource的協定。  UITableViewDataSource拆開後可以看到幾個關鍵字。
-UI:表示這個元件是一個UI介面。
-TableView:表示這個元件是表格視圖。
-DataSource:表示這是某個東西的資料來源。
所以整體來說應該是這樣解釋,這個元件的來源是表格視圖的UI介面。
就是要告訴表格視圖的資料來源是什麼,而我們正透過這個協定來告訴表格視圖該顯示什麼資料。

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

歡迎轉載,請註明出處,感謝。

2012年6月14日 星期四

NSUserDefaults 取得裝置預設的語言

【環境:xCode4.3.2 , ios5.1 , USE ARC】

說明:有些時候,我們在製做app時,可能必須讀取該手機使用者的目前所使用的語言,去判定該如何進行資料庫的搜尋,或者線上搜尋等等,或者其他的應用。
這是利用NSUserDefaults的特性,抓出目前使用者設備中預設的語言。

<以下範例>
 
    NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
    NSArray* languages = [defs objectForKey:@"AppleLanguages"];
    NSString* preferredLang = [languages objectAtIndex:0];
    NSLog(@"%@",preferredLang);
    
    /*
    for (int i=0; i國際設定->語言->語言列表array...[0][1][2][3][4]
    General -> international -> Language -> language list , array[0][1][2][3][4]
    */ 

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

UIDevice抓取目前設備資訊

【環境:xCode4.3.2 , ios5.1】

<以下範例>

主要文件檔案請參考  UIDevice
 
NSLog(@"this : %@",[[UIDevice currentDevice] model]);
//獲取目前使用的設備
NSLog(@"%@",[[UIDevice currentDevice] name]);
// Name of the phone as named by user
NSLog(@"%@",[[UIDevice currentDevice] uniqueIdentifier]);
// A GUID like string
NSLog(@"%@",[[UIDevice currentDevice] systemName]);
// "iPhone OS"
NSLog(@"%@",[[UIDevice currentDevice] systemVersion]);
// "2.2.1"
NSLog(@"%@",[[UIDevice currentDevice] model]);
// "iPhone" on both devices
NSLog(@"%@",[[UIDevice currentDevice] localizedModel]);
// "iPhone" on both devices 

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

2012年6月13日 星期三

libz.1.2.3.dylib not found in iOS5.x, XCode 4.x

說明:在xCode使用libz.1.2.3.dylib編譯發生問題,解決方式如下,因為xcode4.x提升版本,故必須使用libz.1.2.5.dylib,你的專案才可以順利啟動


libz.1.2.3.dylib not found in iOS5


1. 開啓你的 xCode 4.x
2. 從framework中,移除 libz.1.2.3.dylib 
3. 新增一個framework libz.1.2.5 新增方法請參閱加入frameWork到你的app中
4. 執行你的app

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

UIDevice 文件

【環境:xCode4.3.2】

說明:其實從xcode中可以看到,但可以從這份文件當中看出,UIDevice可以替我們做什麼事情,包含
UIDeviceOrientation;//旋轉
UIDeviceBatteryState;//電池
UIUserInterfaceIdiom;//裝置(ipad ,iphone)版本判定

你可以抓出一些資訊,像是
name;              // e.g. "My iPhone"
model;             // e.g. @"iPhone", @"iPod touch"
localizedModel;    // localized version of model
systemName;        // e.g. @"iOS"
systemVersion;     // e.g. @"4.0"
orientation;       // return current device orientation.  this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.
uniqueIdentifier  __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_5_0);  // a string unique to each device based on various hardware info.


<以下官方文件>
 
//
//  UIDevice.h
//  UIKit
//
//  Copyright (c) 2007-2011, Apple Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKitDefines.h>

typedef enum {
    UIDeviceOrientationUnknown,
    UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom
    UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top
    UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right
    UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left
    UIDeviceOrientationFaceUp,              // Device oriented flat, face up
    UIDeviceOrientationFaceDown             // Device oriented flat, face down
} UIDeviceOrientation;

typedef enum {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,   // on battery, discharging
    UIDeviceBatteryStateCharging,    // plugged in, less than 100%
    UIDeviceBatteryStateFull,        // plugged in, at 100%
} UIDeviceBatteryState;              // available in iPhone 3.0

typedef enum {
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIUserInterfaceIdiomPhone,           // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad,             // iPad style UI
#endif
} UIUserInterfaceIdiom;

/* The UI_USER_INTERFACE_IDIOM() macro is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.
 */
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)

#define UIDeviceOrientationIsPortrait(orientation)  ((orientation) == UIDeviceOrientationPortrait || (orientation) == UIDeviceOrientationPortraitUpsideDown)
#define UIDeviceOrientationIsLandscape(orientation) ((orientation) == UIDeviceOrientationLandscapeLeft || (orientation) == UIDeviceOrientationLandscapeRight)

UIKIT_CLASS_AVAILABLE(2_0) @interface UIDevice : NSObject {
 @private
    NSInteger _numDeviceOrientationObservers;
    float     _batteryLevel;
    struct {
 unsigned int batteryMonitoringEnabled:1;
 unsigned int proximityMonitoringEnabled:1;
 unsigned int expectsFaceContactInLandscape:1;
        unsigned int orientation:3;
        unsigned int batteryState:2;
        unsigned int proximityState:1;
    } _deviceFlags;
}

  (UIDevice *)currentDevice;

@property(nonatomic,readonly,retain) NSString    *name;              // e.g. "My iPhone"
@property(nonatomic,readonly,retain) NSString    *model;             // e.g. @"iPhone", @"iPod touch"
@property(nonatomic,readonly,retain) NSString    *localizedModel;    // localized version of model
@property(nonatomic,readonly,retain) NSString    *systemName;        // e.g. @"iOS"
@property(nonatomic,readonly,retain) NSString    *systemVersion;     // e.g. @"4.0"
@property(nonatomic,readonly) UIDeviceOrientation orientation;       // return current device orientation.  this will return UIDeviceOrientationUnknown unless device orientation notifications are being generated.
@property(nonatomic,readonly,retain) NSString    *uniqueIdentifier  __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_5_0);  // a string unique to each device based on various hardware info.

@property(nonatomic,readonly,getter=isGeneratingDeviceOrientationNotifications) BOOL generatesDeviceOrientationNotifications;
- (void)beginGeneratingDeviceOrientationNotifications;      // nestable
- (void)endGeneratingDeviceOrientationNotifications;

@property(nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  // default is NO
@property(nonatomic,readonly) UIDeviceBatteryState          batteryState __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  // UIDeviceBatteryStateUnknown if monitoring disabled
@property(nonatomic,readonly) float                         batteryLevel __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  // 0 .. 1.0. -1.0 if UIDeviceBatteryStateUnknown

@property(nonatomic,getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); // default is NO
@property(nonatomic,readonly)                            BOOL proximityState __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);  // always returns NO if no proximity detector

@property(nonatomic,readonly,getter=isMultitaskingSupported) BOOL multitaskingSupported __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);

@property(nonatomic,readonly) UIUserInterfaceIdiom userInterfaceIdiom __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_2);

- (void)playInputClick __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);  // Plays a click only if an enabling input view is on-screen and user has enabled input clicks.

@end

@protocol UIInputViewAudioFeedback <NSObject>
@optional

@property (nonatomic, readonly) BOOL enableInputClicksWhenVisible; // If YES, an input view will enable playInputClick.

@end

UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;
UIKIT_EXTERN NSString *const UIDeviceBatteryStateDidChangeNotification   __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
UIKIT_EXTERN NSString *const UIDeviceBatteryLevelDidChangeNotification   __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
UIKIT_EXTERN NSString *const UIDeviceProximityStateDidChangeNotification __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0); 

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

判定ios版本的方式

【環境:xCode4.2 , ios5.1 , USE ARC】

說明:因ios版本開發種類持續更新,若有特殊需求,要向下相容,可使用此方法

<以下範例>
 
#import "sys/utsname.h"//記得加入此行

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
// iOS 5 code
//代碼範例使用的是navigation中更改背景圖的方法,ios4以前使用的方法很多種,但蘋果希望目前使用這種方法,故以前的某些方法會被禁用
[self.navigationController.navigationBar setBackgroundImage:[UIImageimageNamed:@"top_bk.png"] forBarMetrics:UIBarMetricsDefault];
}
else {
// iOS 4.x code
}

As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我

ios,判斷目前使用的device為ipad or iphone

【環境:xCode4.3.2 , ios5.0 , USE ARC】

以下是library中所註明的資訊,可在xcode中對使用的關鍵字userInterfaceIdiom按下command+滑鼠左鍵去檢視
typedef enum {
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
    UIUserInterfaceIdiomPhone,           // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad,             // iPad style UI
#endif
} UIUserInterfaceIdiom;

/* The UI_USER_INTERFACE_IDIOM() macro is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.
 */
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)


<以下使用範例>

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
UIViewController*  IPhoneViewController1=[[UIViewController  alloc]init];
self.window.rootViewController=  IPhoneViewController1;
}
else if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) 
{
UIViewController*  IPadViewController1=[[UIViewController  alloc]init];
self.window.rootViewController=  IPadViewController1;
} 

or if you have nib file, you can type
[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];

As always, if you have any question , feel free to contact me.
有任何問題,請聯絡我

2012年6月11日 星期一

sqlite manager匯出資料表,亂碼

【環境:sqlite manager,excel,Numbers】

在mac中,從sqlite manager下載的資料表,用excel打開csv後,中文竟然變成亂碼,這是一件很頭痛的事情,

當然如果你用mac的Numbers打開,應該都是正常的,所以建議用Numbers打開

如果是欄位顯示錯誤的問題,可能在輸出的時候勾選如下圖
請將[Fields Enclosed by] 的 double quotes(''),if necessary (standard) 勾選


輸出的表格就會是正常的

至於在excel中
因為Excel打開檔案時,默認非UTF8的CSV文件

有兩種解決辦法:
1. 可以先用記事本打開csv,另存為ANSI編碼,再用Excel打開。
2. 打開空的Excel,然後在資料->取得外部資料->從文字檔→選擇csv文件,選則UTF-8的編碼(默認是ANSI)。

不過要記得,當你要把資料存回sqlite manager後,要記得選擇正確的格式,不然匯入後,會是亂碼,所以最簡單的做法當然是用Numbers摟。


至於如何在Numbers和excel中修正欄位問題,以後再說。

sqlite manager匯入csv,亂碼

【環境:sqlitemanager,Numbers】
編碼問題一直是程式人員頭痛的問題,從php...信箱編碼...然後資料庫匯入匯出編碼...mac壓縮格式和win壓縮格式 解壓縮後的編碼問題...

一堆有的沒的...
匯入sqlite manager的流程就不多寫了..
主要就是csv檔放進去後資料庫中產生亂碼問題...

準備的資料有
1.已經更正的資料表,execl or Numbers
2.從sqlite manager匯出原本的資料表

我用的是Numbers,將從sqlite manager下載後的csv檔打開後,土法煉鋼的方式,將資料放到csv裡面,最後再用Numbers的輸出,如下圖


將檔案輸出成csv,並選擇你要的格式



2012年6月6日 星期三

ios資料儲存結構

參考資料:

先前介紹過sqlite的使用方式
這次來介紹儲存在手機端ios的目錄結構
如下圖:
ios儲存資料的方式很多種,可以利用.plist或者直接儲存純文字檔,通常數量很龐大的,就用sqlite會比較恰當。

不過當然你可以在你的程式碼中,自己建立新的folder並放置於documents的路徑,像是我為了sqlite資料庫的版本控制,寫了一個plist放在自己建立的folder中,每次打開app就會去比對手機中資料庫版本和目前安裝的版本是否相同。

在這邊稍微解釋一下,通常我們把sqlite資料庫放入app中,並由使用者安裝,安裝過程中,app會必須拷貝一份資料庫,到你手機中app的資源庫中,所以假如你在程式中,沒有加入資料庫是否相同,則每次開啓app,就會把預設的資料庫重新放入你的手機app資源庫中。

舉個例子:
當你製作一份通訊錄,輸入資料後,重新打開app,若無判斷,則app又會把相同名稱的資料庫重新安裝到你的手機中。

我自己除了路徑判斷外,還加上版本控管的功能,這樣以後資料庫可以獨自線上更新,不用透過app store整個更新。或者進階還可以背景更新。

目錄的操作方式請參考:NSFileManager

sqlite於ios程式碼的操作,不錯的網站

SQLite Tutorial


額外補充:

SQL查詢慢的48個原因分析



sqlite manager



【環境:Firefox 12.0、sqlite manager 0.7.7】

說明:
一開始原本也是使用command下指令,去建立sqlite的結構,但無法一覽無疑的介面實在令我很不習慣,畢竟開發程式,可以越方便越好,省去記憶一些開發的指令,例如筆者最近要研究redmine和git這兩個套件,若用command下指令方式去連接,日子一久也難免忘記,到時又必須花費額外的時間研究,有時相當不划算。

所以為了加速app的開發
使用firefox的加載元件manager建構你的sqlite,將會非常快速。

若有些真的很想瞭解基本架構的人,可以參閱此篇文章:sqlite

因為是firefox的開發套件,所以必須去下載firefox,之後進入下方頁面下載manager套件
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

下載後啓動就到firefox的頁面導覽器中,如圖

你可以看到sqlite manager點選進去即可。
操作方法可以看官網介紹。

在這邊就不多說

唯一要注意的是,若你想放到你的xcode project中,則你必須加入一個frameWork叫做libsqlite3.0.dylib

加入framework的方式可以參閱:加入Frameworks到你的專案內
並在你的.h裡面加入#import "sqlite3.h"


在project中快速使用的方式,之後補齊。

sqlite



sqlite是一個輕薄短小的資料庫,
這是sqlite的官網,裡面可以查到一些進階的功能
http://www.sqlite.org/

原始的sqlite建立
若是mac則直接打開command視窗,輸入指令即可
若是win則可以去下載sqlite專用指令視窗

建立sqlite資料庫的方法如下(以mac)
1.開啟command
2.建立的位置,通常在於你目前commad指令視窗目前所指的資料夾位置
3.輸入sqlite3 name.db ,按下enter後,進入sqlite的指令環境
4.建立table 名稱 main_class
CREATE TABLE main_class (
    id INT UNSIGNED NOT NULL,
    name varchar NOT NULL,
    PRIMARY KEY(id)
);

5.將製作好的.db檔,轉成.sqlite檔案,加入到xcode的專案中。
對著xcode左列的檔案按下右鍵,將製作好的.sqlite檔加到Resources資料夾中,做好歸類即可
ps:我看過別人用.rdb檔案建立資料庫,也是直接放入專案當中,直接讀取,似乎也可行,不過沒試過

除了透過以上方法
還可以用sqlite manager還有mamp的方式新增sqlite資料庫

===============================

sqlite建立注意事項
1.先建立一個xcode專案
2.打開command
3.建立sqlite資料庫

方法:
1.下指令:建立資料庫名稱 
sqlite3 name.db  
2.建立資料表方式等等可查詢相關指令


4.退出sqlite3的命令模式,在基本command模式下匯出.db轉成.sqlite
sqlite3 name.db ".dump" > name.sqlite

5.將.sqlite放入xcode的資源庫,加入方法則是對著你要存放的位置按下右鍵,選擇Add Files to xxxxxxxxxxxxx,如圖:



6.
要讓xcode可以讀取就必須添加下列lib到xcode專案中
首先添加 Apple 提供的 sqlite 操作用程序库 ibsqlite3.0.dylib 到工程中。
位置如下
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${VER}.sdk/usr/lib/libsqlite3.0.dylib

在xcode左側欄位的framework中添加

或者

參閱此篇文章

加入Frameworks到你的專案內


7.添加framework後,就在.h檔中加入#import "sqlite3.h"即可使用。