Sean's Note: Xcode
顯示具有 Xcode 標籤的文章。 顯示所有文章
顯示具有 Xcode 標籤的文章。 顯示所有文章

2016年3月23日 星期三

在 didFinishLaunchingWithOptions 時不使用 storyboard 直接載入 nib 檔

  
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;

     // Override point for customization after application launch.

     MyViewController *test = [[MyViewController alloc]     initWithNibName:@"MyViewController" bundle:nil];
     UINavigationController *nav = [[UINavigationController alloc]  initWithRootViewController:test];
     self.window.rootViewController = nav;

     [self.window makeKeyAndVisible];

     return YES;
  }

2016年2月11日 星期四

什麼是 Outlets 和 Referencing Outlets

在 IB 裡的 Show the Connections inspector 頁面,可以看到 Outlets 和 Referencing Outlets,每次基本一定要設定的就是 UIViewController 與 UIView 與之間的連接。

對於 UIViewController 來說,Outlets 可以說是底下的 view 和為 IBOutlet 的那些 properties,所以從圖1 中可以看到 UIViewController 有兩個 Outlets 分別為 view 和 simpleTableView 對應著這個 nib 檔中別名為 View 和 Simple Table View 的元件。而 Referencing Outlets 則為自己被外部的哪些 Objects 所引用,以圖1來說,因為這個 UIViewController 放了一個 UITableView,而 UITableView 擁有 dataSource 和 delegate 的 properties,需要讓他們引用 UIViewController,這也是為什麼需要讓 UIViewController 實作 UITableViewDelegate 和 UITableViewDataSource 。

圖1. File's Owner Connections

另外從 UITableView 的角度來看,他的 Outlets 則是 dataSource 和 delegate,而 Referencing Outlets 則是 simpleTableView。

圖2. UITableView Connections

2014年11月12日 星期三

What is the use of "#pragma mark" in codes?

程式中的 #pragma mark 本身對程式碼並無意義,僅用來幫助組織編排程式,

方便將一群方法分類,以便於在 Jump bar 中快速查詢。

例如:

#pragma mark - 即是加一條分隔線。
#pragma mark Initialization 即是將以下的方法列於 Initialization 標題之下。

圖1. Jump bar