導語:
????好久沒有寫簡書了用踩,最近忙著寫項目和自學Swift。希望在不久的將來可以把項目開源共享給大家破镰,并加入OC和Swift兩個版本来破。一直以來有一個小小的愿望就是寫通俗易懂的項目和Demo供新手學習,讓新手少走我們以前走的彎路货岭。
好了路操,不多說,今天說說一些實用又簡單的知識點吧
一千贯、從View跳轉(zhuǎn)頁面
1.在OC中屯仗,我們從View跳逆到ViewController是這樣的:
ViewController *vc =[[ViewController alloc]init];
UINavigationController *nc = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[nc presentViewController:vc animated:YES completion:nil];
PS:簡單的說就是先拿到根視圖再跳轉(zhuǎn),因為你此刻在View上搔谴。
2.在Swift中魁袜,我們這樣做
let path = NSBundle .mainBundle().pathForResource("驚天魔盜團2", ofType: "mp4")
playerView = AVPlayer(URL:NSURL(fileURLWithPath: path!))
playViewController.player = playerView
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(playViewController, animated: true, completion: nil)```
PS:跟OC道理是一樣的,但Swift要注意其中的可選類型
二敦第、注冊Cell (自定義)
1.在OC中慌核,這樣注冊:
[self.tableView registerNib:[UINib nibWithNibName:@"CRUserCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cellID"];
2.而Swift:
tableView .registerNib(UINib (nibName: "VideoCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: "cell")
三、去掉多余Cell的技巧
1.oc:
self.tableView.tableFooterView = [[UIView alloc]init];
2.Swift
tableView.tableFooterView = UIView()
總結(jié):感受到用swift寫代碼的簡潔性沒申尼?這就是swift的魅力垮卓。。师幕。
后續(xù)更新