2013年5月2日 星期四

UIBarButton init 使用 SystemItem 以及 WithTitle

UIBarButton

兩種 alloc & init 的方法


第一種 , 使用 SystemItem
     UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
                                    initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                   target:self
                                   action:@selector(deleteAction:)];
    saveButton.style = UIBarButtonItemStyleBordered;




第二種 , 使用自定義文字
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Recent" style:UIBarButtonItemStyleBordered target:self action:@selector(deleteAction)];
    saveButton.tag = 1;

2013年5月1日 星期三

TableViewCell ( with Custom ViewCell ) with Stroyboard



第一步
開啟 Storyboard
把 Cell 顯示的元件 透過 Storyboard 都給 拉一拉 , 把 outlet 擺設做好

第二步
新增一個 Class ,


在此我取這個 Class 的名稱為 ByTimeViewCell , 要選 繼承自(Subclass of) UITableViewCell


好了 , 上面兩個圖之後 , 就會產生出  Class ( 有 .h 也有 .m )






第三步 ,
於 ByTimeViewCell.h / .m 添加  outlet 物件的 @property / @synthesize

//  ByTimeViewCell.h
@property (nonatomic, weak) IBOutlet UILabel *firstLabel;
@property (nonatomic, weak) IBOutlet UILabel *secondLabel;
@property (nonatomic, weak) IBOutlet UILabel *thirdLabel;

//  ByTimeViewCell.m
@synthesize firstLabel;
@synthesize secondLabel;
@synthesize thirdLabel;




第四步
去到 Storyboard , 指派 ByTimeViewCell Class 給 Cell 物件
如果 這個 Custom Class 下拉選單 , 沒有出現 剛剛新增的 .h .m Class ,
請看一下 .h .m Class 應該是還沒儲存

如下圖 尚未儲存




如下圖 ( 當下檔案 Command+S 儲存快速鍵 )已經儲存


如果 .h .m 已經儲存 , 但 Class 還是沒有顯示 ,
可嘗試 關閉其他的 xcode Project 專案 , 只剩下 待解決的這個 Project ,
然後整個 xcode 關掉 重開 , Project 重開

再不行 , 還有一招 , 等下再講



第五步
去到 Storyboard 把 outlet 指派 Object
滑鼠指標移到最右邊的 圈圈 , 圈圈 裡頭會多個 + 號 , 然後按著
拉到 預覽可視版型的 物件上頭 再將滑鼠左鍵放開





第六步
去到 TableViewController.m
編輯 引用 .h
 #import "ByTimeViewCell.h"



第七步
去到
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
客制 ViewCell


當上方的框框改寫成如下
ByTimeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

下方的框框
就可以以 . 帶出我們剛剛所新增的 三個 Label 物件
    cell.firstLabel.text = (NSString*)[dictionary objectForKey:@"StayTime"];
    cell.secondLabel.text = [NSString stringWithFormat:@"%02i:%02i", components.hour, components.minute];
    cell.thirdLabel.text = strDist;


這個 Function 第一行 CellIdentifier , ByTimeTableCell 自己命名
static NSString *CellIdentifier = @"ByTimeTableCell";
但需要與 Storyboard 裡頭 相同

如果不相同 , 編譯不會有 Warring , 也不會有 Error ,
情況會是 滑動 Cell 時 , 都是重新再畫 Cell , 比較耗用效能 , 因為沒有重複使用

如果 Storyboard 空白 , 編譯時會有 Warring , 也不會有 Error
但 , 執行起來 , Cell 會空空的 , 帶不出資料





 好了 , 這樣就把 Custom ViewCell 講完了


[EOF]










以各種 string Format 組合後 , 回傳 NSString * , 好用 !~


這個真是好用的參數 , 很符合我的胃口 , 我應該會很常使用到吧 !~

NSString * stRR = [NSString stringWithFormat:@"%@.html", title];

cell.secondLabel.text = [NSString stringWithFormat:@"%02i:%02i", components.hour, components.minute];
 

使用經緯度座標的兩點 歸納得出 KM/M 長度


三角形 斜邊公式 畢氏定理
一邊平方+二邊平方 開庚號 得 斜邊長度

一邊15,二邊15, 得 斜邊長度 21.21xxx 如下
 15,15=>21.21320343559643

依此定理,以經緯度作為一邊與二邊,嘗試歸納出 使用經緯度座標的兩點 KM/M 長度

diff
25.0346, 121.5496
25.0340, 121.5717
-----------------
6,221
36+48841
36,48841 = 開庚號 => 221.0814329607984
221.0814329607984 x 參數 = 2,251.78 M

經緯度距離,轉換成公尺 乘上此參數 x = 10.18529674719125

//////////////
Test A

25.0448, 121.5468
25.0308, 121.5658
-----------------
140,190
(19600+36100) = 開庚號 => 236.0084744241189
236.0084744241189 x 參數 = 2403.81634686154755 M
Result 參數得證


////////
Test B

25.0282, 121.5397
25.0437, 121.5655
-----------------
155, 258
(24025,66564) = 開庚號 => 300.9800657850948
300.9800657850948 x 參數 = 3065.57128501033451 M


-------------------- 分隔線 ---------
幾天之後 補充更新

Okay , 以上是 自己運算的方法 , 結果發現了 一個簡單的 iOS 內建 Function


        // 計算 trashPoint 與 user location 的直線距離
        CLLocation *loc = [[CLLocation alloc] initWithLatitude:fLatitude longitude:fLongitude];
        CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude];
        CLLocationDistance dist = [loc distanceFromLocation:loc2];






PS. 兩個方法的誤差為 加減 7% 之間




ViewController Trigger !~


// ViewController Trigger !~
    [self.navigationController pushViewController:vc animated:YES];