網頁

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"即可使用。

利用delegate傳值

【環境:xCode4.2 , ios5.0】

說明:唯一要注意的應該是,在父框中初始化child後,要將child中所宣告的delegate參數,指向父框(child.delegate_name = self),如程式碼中的第86行。

Download Code
 
#import <UIKit/UIKit.h>

@protocol passValueDelegate

-(void)passString:(NSString *)value;

@end

view1
view2
view1

2012年6月5日 星期二

UIView

【環境:xCode4.2 , ios5.0】

基本UIView,這次主要在於view的移動,還有初階的使用,利用按鈕移動uiview和切換uiview
應用了兩種不同的方法
下一篇會完整介紹UIView的完整功能
比較值得探討的就是
UIViewImage *a1;
a1.frame.size.width & a1.frame.origin.x
一個是自己本身的寬度,另一個是自己本身在父框的初始位置

程式碼下載

截圖:




2012年6月4日 星期一


SA(SA: System Analyst) 系統分析師
在軟體開發團隊中,屬於中高階的基層管理者與領導者。他們除了須具備優秀的文字、語言溝通能力之外,還要有良好的分析、組織、邏輯思考能力。當然也需要有良好的人際關係,以及深厚的技術背景與知識。

系統分析師的工作內容,依階段劃分大致可分為下述幾個階段:系統分析:分析現行系統:確定系統的功能需求;確定系統的資源:保護及績效需求,發展系統架構確定使用單位將面臨的環境及組織變遷。初步設計:劃分作業子系統.擬定子系統的輸入、輸出、介面及作業處理流程:子系統人工作業規格:邏輯質料庫設計:開列系統軟、硬體規格。細步設計:設計實體資料庫:設計人工作業程序;設計文件表格及輸出、入格式;擬訂程式規格及細步流程:確定公用常式與共用程式。系統測試:根據分析階段所訂定的各種功能.加以測試,錯誤資料收集與分析。資料轉換:整理及彙編文件.指派工作人員及進行訓練.進行資料轉換。系統維護:更正系統內潛伏的錯誤:因適應環境的改變而做適度的調整


SD(System Analyst)系統設計師
系統設計師與 SA 所不同的是,SA 所建構的是屬於偏向於領域的概念模型;而 SD 則是根據領域模型,再配合實體的平台,考量其效能、穩定、分散與安全性等,所建構而得的軟體規格模型。SD 的主要產出,仍包括了類別圖、循序圖以及 Database Schema,而這些產出,都會與實體的平台相依。而系統內部的分析與設計,是交由 SA 與 SD 來負責的,而 SA 與 SD 的界限,可以以是否有與實體的平台相依來界定。我們也可以以兩句話來說明分析與設計的關係:“Do the right thing (分析)”and “Do the thing right (設計)”。



RD("R"esearch and "D"evelopment engineer)研發設計工程師,簡稱研發工程師
RD的分類: 一般有可能會遇到二種RD:一種是會不斷發問的RD. 一種是都沒有問題的RD. 然而,常問問題的人大多數是Key man. 是公司重要的人物. 會問問題代表著學習心強. 表達能力良好。

RD在公司的地位: RD部門在公司是重要的單位. 但不代表有地位.只要企劃, 業務或者是老闆有了想法, 不管有理無理, RD就要想辦法把他們的想法具體的實現出來. 採購, 倉管,工程每天追著RD要求配合, 生產線的媽媽,大姐們更是得罪不得, 她們會為了一顆電容擺放位置不好焊來跟你吵半天. 更別提客服部門的抱怨. 


PG(Programming)程式設計師
從每一個資訊的專業職位來看,程式設計師的定義都有一點差異,但基本上你必須要具備幾項基本的資訊技術,才得以勝任多數的資訊工作職位,以下的建議提供參考: 1. 必須至少專精一種程式語言.C,C++,Java都可以. 2. 必須至少專精一種作業系統.Windows,Linux.(可以管理與架設伺服器) 3. 瞭解資料庫. 4. 熟悉網路架構. 5. 要能讀懂英文的技術文件. 


PM (Project Manager) 專案經理
一般而言,比較大的公司才會有專案管理部 (Project Management Department)。負責解決新機種生產、還有新產品研發過程中所有的問題。PM專案管理師隸屬於專案管理部,通稱「專案經理」,簡稱 PM (Project Manager),另外依功能不同,又可稱為「產品經理」 (Product Manager)。所以,作為一個好的PM,必須 1.熟悉該產業的生產製造流程;2.有好的溝通協調、管理能力;3.良好的外語能力(英、日語為主)要了解工廠內各部門(製造部、工程部、測試工程部、產品線、開發採購、倉儲、物流處、關務...等等)的運作,還有研發中心各部門(包括EE、ME、Layout、安規、EMI)的訴求和考量。


DBA (Database Administrator) 資料庫設計與管理人員:資料庫設計與管理人員,最好本身也有寫程式的能力,這樣在管理上會如虎添翼,就這部份的準備方式跟系統平台類似,熱門的SQL、Oracle、Sybase...等,要能有一樣是最擅長的,其他的多少都要懂一點,有很多公司都是從SQL開始,到後來轉成Oracle,所以如果跟不上企業的轉變,會是很大的缺憾。


MIS (Management Information System)管理資訊系統,即網管人員
MIS依管理決策之需要,應用資料庫將一個機構之資訊整合處理分析,以便即時提供各階層管理者使用。

VD(visual designer) 視覺設計師


持續補完.....>

狀態列statusBar

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

說明:在xCode中,對setStatusBarStyle這個標籤,按下ctrl+滑鼠左鍵,可察看相關可設定的資訊,關於在xCode中,利用plist更改預設的方式,就不多說

<以下範例>
 
//設定類型
[[UIApplication shareApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];

//特定透明
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];

//隱藏狀態列
[[UIApplication shareApplication] setStatusBarHidden:YES];

IDE 、 SDK 、 API

整合開發環境(Integrated Development Environment,簡稱 IDE也有人稱為Integration Design Environment、Integration Debugging Environment)
是一種輔助程式開發人員開發軟體應用軟體

軟體開發套件Software Development Kit, 即 SDK
一般是一些被軟體工程師用於為特定的軟體包軟體框、硬體平台、作業系統等建立應用軟體的開發工具的集合。

應用程序介面英語Application Programming Interface,簡稱:API
又稱為應用編程介,就是軟體系統不同組成部分銜接的約定。由於近年來軟體的規模日益龐大,常常會需要把複雜的系統劃分成小的組成部分,編程介面的設計十分重要。程序設計的實踐中,編程介面的設計首先要使軟體系統的職責得到合理劃分。良好的介面設計可以降低系統各部分的相互依賴,提高組成單元的內聚性降低組成單元間的耦合程度,從而提高系統的維護性和擴展性。

frame & bounds

此圖為網路截取

view的觀念

座標系中比較常用的幾個概念是
Frame:Frame指定了View相對於其父View座標系的位置和大小
Bounds:Bounds則是view相對於自身坐標系的位置和大小,bounds的起點通常都是(0,0),但是有些時候也可以透過這個屬性來對view的顯示範圍進行更靈活的控制。
Center:顧名思義就是view的Frame的中心。

frame的CGPoint是指父類view的原點坐標位置
而bounds則是只左上角自身坐標系的位置

bounds & frame的程式範例,可看到....frame & bounds之間的關係....
 
 UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(101.0f, 100.0f, 51.0f, 50.0f)];
 v1.backgroundColor = [UIColor yellowColor];
    
 NSLog(@"frame_x : %f, frame_y : %f",v1.frame.origin.x,v1.frame.origin.y);
 NSLog(@"frane_w : %f, frame_h : %f",v1.frame.size.width,v1.frame.size.height);
    
 NSLog(@"bounds_x : %f,bounds_y : %f",v1.bounds.origin.x,v1.bounds.origin.y);
 NSLog(@"bounds_w : %f,bounds_h : %f",v1.bounds.size.width,v1.bounds.size.height);
    
 [self.view addSubview:v1]; 

顯示出來的結果為
2012-06-11 10:09:33.064 TAAZA[489:f803] frame_x : 101.000000, frame_y : 100.000000
2012-06-11 10:09:33.065 TAAZA[489:f803] frane_w : 51.000000, frame_h : 50.000000
2012-06-11 10:09:33.065 TAAZA[489:f803] bounds_x : 0.000000,bounds_y : 0.000000
2012-06-11 10:09:33.066 TAAZA[489:f803] bounds_w : 51.000000,bounds_h : 50.000000

最後你可以試試在一個view上面addSubView疊加一個view後,用super.view.frame.origin.x等等之類的,看可否得知第一個view的frame的x位置 同理可證使用其他的位置去抓出父view的位置或者size

osx10.7 顯示user的library

更新到10.7的使用者們,或許會覺得很奇怪,以前個人帳戶下的library跑去哪了
只需於command中鍵入

chflags nohidden ~/Library 


就可以把遺失的library給取回
妳可以自己去設定nohidden或者hidden去將資料夾給隱藏

AVFoundation應用、Google_TTS

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

說明:
以uitabBarController為基礎框架,自定義tabBar,我的tabBarItem用的是30x30的大小,且背景須為透明,顏色為淺色系。
使用uitextview、AVFoundation應用、Google_TTS。
其中tts的部份加入,中英文判斷。
應用到了一點QuartzCore去處理uitextview的外框。

值得注意的還有tts若想用其他語言發音
http://translate.google.com/translate_tts?tl=en&q=text
則更改紅字的部份,此部份為countryCode

故此範例須引用
#import <AVFoundation/AVFoundation.h> 
#import <QuartzCore/QuartzCore.h>
引用的protocol有以下兩個
<UITabBarDelegate,UITabBarControllerDelegate>
<UITextViewDelegate>

※若你的音效程式碼運行正確,但實機測試卻撥不出來,可以檢查<你iphone的震動的按鈕是否打開>。

※若simulation也無聲音,大概就必須檢查你的程式碼stop & pause部分代碼,是否和play搞混。


範例下載  若只需單純的tts 參考,此部份提供當初我網路上參考tts的程式






<以下部分程式碼範例-主要為textview應用和google tts的應用>
 
//
//  view2.m
//  sound & tts
//
//  Created by jhaoheng on 2012/6/1.
//  Copyright (c) 2012年 __n11_studio__. All rights reserved.
//

#import "view2.h"

//由於本範例有使用到 Layer 類別的方法,所以必須先匯入其對應的標頭檔和 Framework。
#import <QuartzCore/QuartzCore.h>

@implementation view2

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        //self.title = @"three";
        UIImage *img_speak = [UIImage imageNamed:@"google.png"];
        UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"G_TTS" image:img_speak tag:1]; 
        self.tabBarItem = item3;
        
        /*
        The item’s image. If nil, an image is not displayed.
        
        The images displayed on the tab bar are derived from this image. If this image is too large to fit on the tab bar, it is scaled to fit. The size of an tab bar image is typically 30 x 30 points. The alpha values in the source image are used to create the unselected and selected images—opaque values are ignored.
        */
        /*
         if you want to create icons for iPhone UITabBar ,you can read this website
         http://steveweller.com/articles/toolbar-icons/
        */
    }
    return self;
}

- (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.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    input_text = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, 300, 150)];
    input_text.font = [UIFont fontWithName:@"Arial" size:20];
    input_text.textColor = [UIColor whiteColor];
    input_text.delegate = self;
    input_text.backgroundColor = [UIColor whiteColor];
    input_text.text = @"you can type something in this frame and click the speaker button to pronounce";
    input_text.returnKeyType = UIReturnKeyDefault;
    input_text.keyboardType = UIKeyboardTypeDefault;
    /*
     autocapitalizationType — 首字大寫
     autocorrectionType — 自動更正錯字
     enablesReturnKeyAutomatically — 確認使用者有輸入文字後才啟用return鍵
     keyboardAppearance — 鍵盤外型
     keyboardType — 鍵盤種類
     returnKeyType — return鍵的類型
     secureTextEntry — 隱藏輸入的文字
    */
    //設定是否可捲動
    input_text.scrollEnabled = YES;
    //自適應高度
    //text.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    
    //設定橘色背景與棕色邊框
    [input_text setBackgroundColor:[UIColor orangeColor]];
    [[input_text layer] setBorderColor:[[UIColor brownColor] CGColor]];
    //邊框粗細
    [[input_text layer] setBorderWidth:1.5];
    //設定圓角程度
    [[input_text layer] setCornerRadius:20];
    /*指定內文字體大小並置中
    [text setFont:[UIFont boldSystemFontOfSize:50.0]];
    [text setTextAlignment:UITextAlignmentCenter];
    */
    //設定無法再被編輯
    [input_text setEditable:YES];
     
    //使內文保持在UITextView邊框之內
    [input_text setClipsToBounds: YES];
    [self.view addSubview:input_text];
    
    UIButton *speaker = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [speaker setTitle:@"speaker" forState:UIControlStateNormal];
    [speaker setTitle:@"connect" forState:UIControlStateHighlighted];
    speaker.frame = CGRectMake(20, 295, 280, 40);
    [speaker addTarget:self action:@selector(machine_speak) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:speaker];
}


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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -uibutton
-(void)machine_speak
{
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"file.mp3"];
    NSString *urlString;
    if ([input_text.text canBeConvertedToEncoding: NSASCIIStringEncoding]) {//如果是英語
        urlString = [NSString stringWithFormat:@"http://www.translate.google.com/translate_tts?tl=en&q=%@",input_text.text];
    }  
    else { //如果是非英語 
        urlString = [NSString stringWithFormat:@"http://www.translate.google.com/translate_tts?tl=zh-TW&q=%@",input_text.text];
    } 
    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
    [request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" forHTTPHeaderField:@"User-Agent"];
    NSURLResponse* response = nil;
    NSError* error = nil;
    NSData* data = [NSURLConnection sendSynchronousRequest:request
                                         returningResponse:&response
                                                     error:&error];
    [data writeToFile:path atomically:YES];
    
    NSError *err;
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) 
    {    
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&err];
        player.volume = 0.8f;
        [player prepareToPlay];
        [player setNumberOfLoops:0];
        [player play];    
    }
     
}

#pragma mark - UITextView Delegate Methods     

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)closetext
{    
    if ([closetext isEqualToString:@"\n"]) {    
        
        [input_text resignFirstResponder];    
        
        return NO;    
        
    }
    return YES;    
}

@end