2017年11月30日 星期四
測試app遇到記憶體不足的情況
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
2017年11月29日 星期三
2016年6月22日 星期三
筆記一下rxswift遇到disposeBag的scope問題
//userRestoreObservable被訂閱時,會去server抓東西
//原本是在DataUpdate這個struct中寫disposeBag,setupInitialInfo完會釋放裡面的observable。
//但當userRestoreObservable的next closure做完,裡面的物件都被釋放掉,
於是setupInitialInfo的disposeBag也被釋放,就接不到server回傳時的callback。
//解決方法是把disposeBag改成外部注入,讓它被宣告在closure外部,這樣才可以保證裡面的closure不會先被釋放掉。
func fetchUserByRestoreInfo(restoreInfo: RestoreInfo, completion: (()->Void)?) {
let disposeBag = DisposeBag()
userRestoreObservable(restoreInfo).subscribeNext { (newUserObj) in
prettyLog(newUserObj.debugDescription)
var userDefault = self.userDefault
userDefault.userPackage = newUserObj
userDefault.isNewLounch = false
DataUpdate().setupInitialInfo(disposeBag)
completion?()
}.addDisposableTo(disposeBag)
}
2016年6月16日 星期四
present出二個modelView之後要dismiss回去rootViewController (iOS5.0之後適用)
if let presentingVC = self?.presentingViewController {
self?.dismissViewControllerAnimated(false, completion: {
presentingVC.dismissViewControllerAnimated(false, completion: nil)
})
}
//這裡的重點是presentingVC是把當下VC給present出來的VC,你也可以看作parentViewController。
而你當前VC所present出來的VC,會叫presentedVC,也可以看作是childrenViewController.
presentingVC ---(present)---> yourViewController ---(present)---> presentedVC
2016年6月3日 星期五
記錄一個lazy的應用場景
放在首頁的一個tableview要用到的datasource必須跟server查詢才能取得,
但跟server查詢之前要先等到launch時的資料已經下載完。
因為我是用RxSwift所以我要用Observable做為datasource竹
這時候你在init的時候就可以把datasource的資料來源先設為lazy的參數,
但跟server查詢之前要先等到launch時的資料已經下載完。
因為我是用RxSwift所以我要用Observable做為datasource竹
這時候你在init的時候就可以把datasource的資料來源先設為lazy的參數,
lazy var items: Observable<[SectionModel<String, DepositList.Option>]>? = self.getItems()
它就會先init好,但等到你真正要的時候才去subscribe。
2016年5月31日 星期二
讓tableCell的分隔線從頭連到尾(iOS 8以後)
//viewDidLoad
tableView.layoutMargins = UIEdgeInsetsZero
tableView.separatorInset = UIEdgeInsetsZero
//setup Cell
cell!.layoutMargins = UIEdgeInsetsZero
2016年5月25日 星期三
UIScrollView裡面的點擊事件反應很慢
var delaysContentTouches: Bool
If the value of this property is
同樣一個UISegmentedControl,加在ScrollView裡面反應就異常的慢,原來是UIScrollView的subview上的touch事件會被延遲,目的是為了確定當次的手勢不是要滑動。
如果你想讓你的scrollView以點擊事件為主:
yourScrollView.delaysContentTouches = false
如果你想讓你的scrollView以滑動事件為主:
yourScrollView.delaysContentTouches = true
If the value of this property is
true, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is false , the scroll view immediately callstouchesShouldBegin:withEvent:inContentView:. The default value is true.同樣一個UISegmentedControl,加在ScrollView裡面反應就異常的慢,原來是UIScrollView的subview上的touch事件會被延遲,目的是為了確定當次的手勢不是要滑動。
如果你想讓你的scrollView以點擊事件為主:
yourScrollView.delaysContentTouches = false
如果你想讓你的scrollView以滑動事件為主:
yourScrollView.delaysContentTouches = true
訂閱:
文章 (Atom)