将:
if let cellContentView = textField.superview { gLog.verbose(“cellContentView=\(cellContentView)”) //cellContentView=<UITableViewCellContentView: 0x7b97a420; frame = (0 0; 320 43.5); gestureRecognizers = <NSArray: 0x7b9ebcc0>; layer = <CALayer: 0x7b961830>> if let cellView = cellContentView.superview { gLog.verbose(“cellView=\(cellView)”) //cellView=<Sales_App.LeftLabelRightTextfieldTableViewCell: 0x7d38c400; baseClass = UITableViewCell; frame = (0 794; 320 44); autoresize = W; layer = <CALayer: 0x7b961800>> if cellView is UITableViewCell { let curCell = cellView as! UITableViewCell gLog.verbose(“curCell=\(curCell)”) //curCell=<Sales_App.LeftLabelRightTextfieldTableViewCell: 0x7d38c400; baseClass = UITableViewCell; frame = (0 794; 320 44); autoresize = W; layer = <CALayer: 0x7b961800>> if let curIndexPath = self.customerDetailTableview.indexPathForCell(curCell) { self.customerDetailTableview.scrollToRowAtIndexPath(curIndexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: false) } } } } |
变成:
if let cellView = textField.superview?.superview where cellView is UITableViewCell { gLog.verbose(“cellView=\(cellView)”) //cellView=<Sales_App.LeftLabelRightTextfieldTableViewCell: 0x7c1ffe00; baseClass = UITableViewCell; frame = (0 794; 320 44); autoresize = W; layer = <CALayer: 0x7ce43e70>> if let curIndexPath = self.customerDetailTableview.indexPathForCell(cellView as! UITableViewCell) { gLog.verbose(“curIndexPath=\(curIndexPath)”) //curIndexPath=<NSIndexPath: 0x7af4ada0> {length = 2, path = 4 – 6} self.customerDetailTableview.scrollToRowAtIndexPath(curIndexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: false) } } |
即可。
-》简洁,明了,含义明确。
转载请注明:在路上 » 【整理】swift心得:option值,where,as!的效果