Skip to content

Commit

Permalink
Two Segues
Browse files Browse the repository at this point in the history
  • Loading branch information
BestKora committed Nov 25, 2018
1 parent 9ffe923 commit f4913e1
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 66 deletions.
50 changes: 35 additions & 15 deletions ImageGallery/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="fge-hc-XwM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="yOK-He-cOO">
<device id="ipad9_7" orientation="landscape">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -15,7 +15,7 @@
<objects>
<collectionViewController id="lNy-wU-Qmh" customClass="ImageGalleryCollectionViewController" customModule="ImageGallery" customModuleProvider="target" sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" id="ujC-rb-2AE">
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
<rect key="frame" x="0.0" y="0.0" width="703.5" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="XpM-ao-rTw">
Expand Down Expand Up @@ -57,7 +57,7 @@
</connections>
</collectionViewCell>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="DropPlaceholderCell" id="3eH-ko-hDQ">
<rect key="frame" x="362" y="0.0" width="300" height="300"/>
<rect key="frame" x="403.5" y="0.0" width="300" height="300"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="300" height="300"/>
Expand Down Expand Up @@ -91,7 +91,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="QFN-SG-REC" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="iPT-un-f3h">
<rect key="frame" x="0.0" y="20" width="1024" height="50"/>
<rect key="frame" x="0.0" y="20" width="703.5" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -101,21 +101,21 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Xae-5g-ZO9" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="55.664062499999993" y="147.65625"/>
<point key="canvasLocation" x="19" y="134"/>
</scene>
<!--Image View Controller-->
<scene sceneID="o2Z-Xn-7iI">
<objects>
<viewController id="a2w-LW-1y7" customClass="ImageViewController" customModule="ImageGallery" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="NI9-PS-G6H">
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
<rect key="frame" x="0.0" y="0.0" width="703.5" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="NfT-kV-qmn">
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
<rect key="frame" x="0.0" y="0.0" width="703.5" height="768"/>
</scrollView>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="sVM-Kv-SBl">
<rect key="frame" x="493.5" y="400.5" width="37" height="37"/>
<rect key="frame" x="333.5" y="400.5" width="37" height="37"/>
<color key="color" red="0.0" green="0.0" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</activityIndicatorView>
</subviews>
Expand Down Expand Up @@ -145,15 +145,15 @@
<objects>
<tableViewController id="V2J-w4-FFF" customClass="GalleriesTableViewController" customModule="ImageGallery" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="xqc-s9-RJM">
<rect key="frame" x="0.0" y="0.0" width="1024" height="768"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="768"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Gallery Cell" rowHeight="90" id="lac-Ud-gh0" customClass="GalleryTableViewCell" customModule="ImageGallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="1024" height="90"/>
<rect key="frame" x="0.0" y="28" width="320" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="lac-Ud-gh0" id="vly-P3-TnC">
<rect key="frame" x="0.0" y="0.0" width="1024" height="89.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="89.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" enabled="NO" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Ixc-zu-E6s">
Expand All @@ -175,24 +175,28 @@
<color key="backgroundColor" red="0.016804177310000001" green="0.19835099580000001" blue="1" alpha="0.42318600169999998" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="nameTextField" destination="Ixc-zu-E6s" id="i1B-91-UZc"/>
<segue destination="QFN-SG-REC" kind="showDetail" identifier="Show Gallery" id="1Rn-q6-d1m"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Title Cell" textLabel="xPS-I9-nB2" rowHeight="90" style="IBUITableViewCellStyleDefault" id="2eq-ZC-aeH">
<rect key="frame" x="0.0" y="118" width="1024" height="90"/>
<rect key="frame" x="0.0" y="118" width="320" height="90"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="2eq-ZC-aeH" id="FkV-Gl-5sh">
<rect key="frame" x="0.0" y="0.0" width="1024" height="89.5"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="89.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="xPS-I9-nB2">
<rect key="frame" x="20" y="0.0" width="984" height="89.5"/>
<rect key="frame" x="16" y="0.0" width="288" height="89.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="QFN-SG-REC" kind="showDetail" identifier="Not Show Gallery" id="vuH-wk-HMs"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
Expand All @@ -218,7 +222,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="fge-hc-XwM" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="S8Y-Cm-Hjd">
<rect key="frame" x="0.0" y="20" width="1024" height="50"/>
<rect key="frame" x="0.0" y="20" width="320" height="50"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -230,5 +234,21 @@
</objects>
<point key="canvasLocation" x="19" y="-568"/>
</scene>
<!--Split View Controller-->
<scene sceneID="ApG-5B-lRq">
<objects>
<splitViewController id="yOK-He-cOO" sceneMemberID="viewController">
<connections>
<segue destination="fge-hc-XwM" kind="relationship" relationship="masterViewController" id="fMC-75-MOR"/>
<segue destination="QFN-SG-REC" kind="relationship" relationship="detailViewController" id="iSs-yU-qlD"/>
</connections>
</splitViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ukg-z1-RoK" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-707" y="-336"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="1Rn-q6-d1m"/>
</inferredMetricsTieBreakers>
</document>
111 changes: 86 additions & 25 deletions ImageGallery/GalleriesTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,38 @@ class GalleriesTableViewController: UITableViewController {
ImageGallery(name: "Галерея 66")
]
]
let im1 = ImageModel(url: URL(string:
"http://www.planetware.com/photos-large/F/france-paris-eiffel-tower.jpg")!,
aspectRatio: 0.67)
let im2 = ImageModel(url: URL(string:
"https://adriatic-lines.com/wp-content/uploads/2015/04/canal-of-Venice.jpg")!,
aspectRatio: 1.5)

let im3 = ImageModel(url: URL(string:
"http://www.picture-newsletter.com/arctic/arctic-12.jpg")!,
aspectRatio: 0.8)
imageGalleries[0][0].images = [im1,im2,im3]
}

private func galleryName(at indexPath: IndexPath) -> String {
return imageGalleries[indexPath.section][indexPath.row].name
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
selectRow(at: IndexPath(row: 0, section: 0))
let currentIndex = lastIndexPath != nil
? lastIndexPath!
: IndexPath(row: 0, section: 0)
selectRow(at: currentIndex)
}

override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if splitViewController?.preferredDisplayMode != .primaryOverlay {
splitViewController?.preferredDisplayMode = .primaryOverlay
}
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
Expand Down Expand Up @@ -75,10 +100,6 @@ class GalleriesTableViewController: UITableViewController {
}
return cell
}

private func galleryName(at indexPath: IndexPath) -> String {
return imageGalleries[indexPath.section][indexPath.row].name
}

override func tableView(_ tableView: UITableView,
titleForHeaderInSection section: Int) -> String? {
Expand Down Expand Up @@ -118,20 +139,6 @@ class GalleriesTableViewController: UITableViewController {
}
}
}

private func selectRow(at indexPath: IndexPath,
after timeDelay: TimeInterval = 0.0) {
if tableView(self.tableView,
numberOfRowsInSection: indexPath.section) >= indexPath.row {
Timer.scheduledTimer(withTimeInterval: timeDelay,
repeats: false,
block: { (timer) in
self.tableView.selectRow(at: indexPath,
animated: false,
scrollPosition: .none)
})
}
}

override func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath
Expand Down Expand Up @@ -162,14 +169,68 @@ class GalleriesTableViewController: UITableViewController {
}
}

/*

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
private var lastIndexPath: IndexPath?

private var splitViewDetailCollectionController: ImageGalleryCollectionViewController? {
let navCon = splitViewController?.viewControllers.last as? UINavigationController
return navCon?.viewControllers.first as? ImageGalleryCollectionViewController
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if let identifier = segue.identifier {
switch identifier {
case "Show Gallery":
if let cell = sender as? GalleryTableViewCell,
let indexPath = tableView.indexPath(for: cell) {
if let ivc = segue.destination.contents as?
ImageGalleryCollectionViewController {
lastIndexPath = indexPath
ivc.imageGallery =
imageGalleries[indexPath.section][indexPath.row]
ivc.title =
imageGalleries[indexPath.section][indexPath.row].name
ivc.collectionView?.isUserInteractionEnabled = true
ivc.navigationItem.leftBarButtonItem =
splitViewController?.displayModeButtonItem
}
}
case "Not Show Gallery":
if let cell = sender as? UITableViewCell,
let indexPath = tableView.indexPath(for: cell){
if let ivc = segue.destination.contents as?
ImageGalleryCollectionViewController {
lastIndexPath = indexPath
let newName = "Recently Deleted '" +
imageGalleries[indexPath.section][indexPath.row].name + "'"
ivc.imageGallery = ImageGallery (name: newName)
ivc.title = newName
ivc.collectionView?.isUserInteractionEnabled = false
ivc.collectionView?.backgroundColor = UIColor.gray
ivc.navigationItem.leftBarButtonItem =
splitViewController?.displayModeButtonItem
}
}
default:
break
}
}
}

private func selectRow(at indexPath: IndexPath,
after timeDelay: TimeInterval = 0.0) {
if tableView(self.tableView,
numberOfRowsInSection: indexPath.section) >= indexPath.row {
Timer.scheduledTimer(withTimeInterval: timeDelay,
repeats: false,
block: { (timer) in
self.tableView.selectRow(at: indexPath,
animated: false,
scrollPosition: .none)
})
}
}
*/

}
2 changes: 1 addition & 1 deletion ImageGallery/ImageGallery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct ImageModel{
var aspectRatio: Double
}

struct ImageGallery {
class ImageGallery {
var name: String
var images = [ImageModel]()

Expand Down
Loading

0 comments on commit f4913e1

Please sign in to comment.