2013年5月13日 星期一

Storyboard 入門文章整理

這邊將這兩週所閱讀的文章進行個簡單的整理,方便日後搜尋。

dismiss 與 present

畫面切換的method在iOS6.0之後有些許的調整,
目前在使用上是沒有問題的,就是換出現警告。

dismissViewControllerAnimated:completion: 取代 dismissModalViewControllerAnimated: presentViewController:animated:completion: 取代 presentModalViewController:animated:

Cell 使用不同的背景

之前工作上有個需求,希望第一跟最後一個Cell能加上陰影,
當時沒想出解決的方法。

今天看到下面這篇文章, 覺得這方式也不錯,或許是個方式,這邊記錄一下。
有機會再來試一下。

http://www.appcoda.com/ios-programming-customize-uitableview-storyboard
- (UIImage *)cellBackgroundForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger rowCount = [self tableView:[self tableView] numberOfRowsInSection:0];
    NSInteger rowIndex = indexPath.row;
    UIImage *background = nil;
    
    if (rowIndex == 0) {
        background = [UIImage imageNamed:@"cell_top.png"];
    } else if (rowIndex == rowCount - 1) {
        background = [UIImage imageNamed:@"cell_bottom.png"];
    } else {
        background = [UIImage imageNamed:@"cell_middle.png"];
    }
    
    return background;
}

2013年5月7日 星期二

Storyboard 相關資訊及注意事項

Storyboard需iOS 5、XCode 4.2以上版本才開始支援。
  1. 其基礎為xib,增加其功能,與xib最明顯不同處在一個xib檔,僅代表一個screen,而一個strotyboard可包含多個screen。
  2. 一個專案中不限制只能有一個Storyboard檔案,可多個檔案並存,但若此取此方式,這可能就失去Storyboard其原有的意義了。
    但是,若同時支援iPhone與iPad,Storyboard需分別使用不同的Storyboard檔案,並在info.plist中進行相關設定。
  3. 採用Storyboard的專案除可使用Storyboard進行開發之外,也可同時使用xib進行開發
  4. 在view controller切換,除了以原先以model或是navigate controller push的方式之外,另外增加了以segue方式切換。
注意事項:
  1. 採取Storyboard多人協同開發,並進行版本控制時,與xib有想同的問題,若同時對同一檔案維護時,可能會發生衝突問題。
  2. 另外,在iOS 6與iPhone 5釋出時,為配合iPhone 5 4吋螢幕,Storyboard增加了Autolayout功能,但該功能限制要最低版本為iOS 6以上,若在iOS 5編譯時程式會直接crash。

2013年3月11日 星期一

- drawRect: CGRectInset

最近用到了一個指令
CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
老是搞不清楚運作的方式
所以做了個實驗並將果記錄下來

rect = (0, 0 ,320, 480)
     
     CGRectInset(rect, 0, 0)    =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 480.000000
     CGRectInset(rect, 10, 0)   =>    x = 10.000000,  y = 10.000000,  width = 300.000000, height = 480.000000
     CGRectInset(rect, 20, 0)   =>    x = 20.000000,  y = 20.000000,  width = 280.000000, height = 480.000000
     CGRectInset(rect, 0, 10)   =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 460.000000
     CGRectInset(rect, 0, 20)   =>    x = 0.000000,   y = 0.000000,   width = 320.000000, height = 440.000000
     CGRectInset(rect, 10, 20)  =>    x = 10.000000,  y = 10.000000,  width = 300.000000, height = 440.000000
    
     CGRect newRect = CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)
     
     newRect.origin.x = dx;
     newRect.origin.y = dx;
     newRect.size.width = rect.size.wide - dy * 2
     newRect.size.height = rect.size.height - dy * 2

2013年2月26日 星期二

錯誤訊息_2013-02-26

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__nsarraym: data-blogger-escaped-0x75828d0=""> was mutated while being enumerated.'
*** First throw call stack:
(0x15a1012 0x12aee7e 0x1629cc5 0x3ec3 0x12c2705 0x1f62c0 0x1f6258 0x2b7021 0x2b757f 0x2b66e8 0x225cef 0x225f02 0x203d4a 0x1f5698 0x2603df9 0x2603ad0 0x1516bf5 0x1516962 0x1547bb6 0x1546f44 0x1546e1b 0x26027e3 0x2602668 0x1f2ffc 0x2bdd 0x2b05)
libc++abi.dylib: terminate called throwing an exception

今天遇到了一個問題
Google "NSGenericException"之後找到了問題
起因是因為我要刪除Array中某元素所造成

這問題主因簡單來說就是太多層了
系統來不及反映所導致

比如說:我要刪除 a.array[0].array[1]
這樣就有可能會發生問題

2013年2月23日 星期六

Responds To Selector

在@select時
如果沒有選好常會有當掉的狀況
搜尋了一下
有篇文章的方法不錯記錄下來
http://blog.csdn.net/dongdongdongjl/article/details/8498555

使用respondsToSelector@select(Method)
來判斷是否有此Method
這樣就比較不會當掉了