Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Add】Expanded the function of deleting cells And Provide usage examples #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Former-Demo/Former-Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
181DCBF025D26E6D002C780F /* DeleteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181DCBEF25D26E6D002C780F /* DeleteViewController.swift */; };
2A53250E1BE48C3F00E4A3F2 /* EditProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A53250D1BE48C3F00E4A3F2 /* EditProfileViewController.swift */; };
2A5325101BE4935700E4A3F2 /* ProfileImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A53250F1BE4935700E4A3F2 /* ProfileImageCell.swift */; };
2A5325151BE4A55D00E4A3F2 /* ProfileFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5325141BE4A55D00E4A3F2 /* ProfileFieldCell.swift */; };
Expand Down Expand Up @@ -71,6 +72,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
181DCBEF25D26E6D002C780F /* DeleteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteViewController.swift; sourceTree = "<group>"; };
2A53250D1BE48C3F00E4A3F2 /* EditProfileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditProfileViewController.swift; sourceTree = "<group>"; };
2A53250F1BE4935700E4A3F2 /* ProfileImageCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileImageCell.swift; sourceTree = "<group>"; };
2A5325141BE4A55D00E4A3F2 /* ProfileFieldCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileFieldCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -198,6 +200,7 @@
2AA777A41BECED6200900B01 /* AddEventViewController.swift */,
2AA777B21BEE80A800900B01 /* LoginViewController.swift */,
2AA777AA1BED4BF000900B01 /* CustomCellViewController.swift */,
181DCBEF25D26E6D002C780F /* DeleteViewController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -331,6 +334,7 @@
2AC381531BA447D3009C7EFF /* ExampleViewController.swift in Sources */,
2AC3814E1BA447D3009C7EFF /* AppDelegate.swift in Sources */,
2AA777B31BEE80A800900B01 /* LoginViewController.swift in Sources */,
181DCBF025D26E6D002C780F /* DeleteViewController.swift in Sources */,
2AA777A51BECED6200900B01 /* AddEventViewController.swift in Sources */,
2AA777B51BEE86B000900B01 /* Login.swift in Sources */,
2A53250E1BE48C3F00E4A3F2 /* EditProfileViewController.swift in Sources */,
Expand Down
51 changes: 51 additions & 0 deletions Former-Demo/Former-Demo/Controllers/DeleteViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// DeleteViewController.swift
// Former-Demo
//
// Created by ZhangShuai on 2021/2/9.
// Copyright © 2021 Ryo Aoyama. All rights reserved.
// This is a simple removable cell, available IOS 11 later

import UIKit
import Former

final class DeleteViewController: FormViewController {

override func viewDidLoad() {
super.viewDidLoad()
configure()
}

private func configure() {
title = "Delete Cell"
tableView.contentInset.top = 10
tableView.contentInset.bottom = 30
tableView.contentOffset.y = -10

// Create RowFomers
let titleRow = LabelRowFormer<CenterLabelCell>.init().configure(handler: {
$0.text = "General Cell"
})

let removableCell = LabelRowFormer<CenterLabelCell>.init().configure(handler: {
$0.text = "removable Cell"
$0.isCanDeleted = true
$0.deletedTitle = "remove cell"
})
.deletingCompleted { (row, index) in
print("cell has benn removed at \(index) ")
}

// Create Headers
let createHeader: (() -> ViewFormer) = {
return CustomViewFormer<FormHeaderFooterView>()
.configure {
$0.viewHeight = 20
}
}

// Create SectionFormers
let titleSection = SectionFormer(rowFormer: titleRow, removableCell).set(headerViewFormer: createHeader())
former.append(sectionFormer: titleSection)
}
}
6 changes: 5 additions & 1 deletion Former-Demo/Former-Demo/Controllers/TopViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ final class TopViewContoller: FormViewController {
let defaultRow = createMenu("All Defaults") { [weak self] in
self?.navigationController?.pushViewController(DefaultsViewController(), animated: true)
}
let deleteRow = createMenu("Delete Cell") { [weak self] in
self?.navigationController?.pushViewController(DeleteViewController(), animated: true)
}


// Create Headers and Footers

Expand All @@ -84,7 +88,7 @@ final class TopViewContoller: FormViewController {

// Create SectionFormers

let realExampleSection = SectionFormer(rowFormer: editProfileRow, addEventRow, loginRow)
let realExampleSection = SectionFormer(rowFormer: editProfileRow, addEventRow, loginRow, deleteRow)
.set(headerViewFormer: createHeader("Real Examples"))
let useCaseSection = SectionFormer(rowFormer: exampleRow, customCellRow)
.set(headerViewFormer: createHeader("Use Case"))
Expand Down
23 changes: 11 additions & 12 deletions Former-Demo/Former-Demo/Resources/LoginViewController.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="FLk-xs-t2Q">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="FLk-xs-t2Q">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Login View Controller-->
Expand All @@ -14,24 +16,22 @@
<viewControllerLayoutGuide type="bottom" id="dHn-nh-avc"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8ae-zI-9Zi">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mDt-3d-EKK" customClass="UIControl">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="862"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="jsy-Gq-nsL">
<rect key="frame" x="150" y="100" width="300" height="400"/>
<animations/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<rect key="frame" x="57" y="231" width="300" height="400"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="400" id="DJu-Ob-igc"/>
<constraint firstAttribute="width" constant="300" id="Wbl-rN-MSA"/>
</constraints>
</tableView>
</subviews>
<animations/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.70182291666666663" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.70182291666666663" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="jsy-Gq-nsL" firstAttribute="centerX" secondItem="mDt-3d-EKK" secondAttribute="centerX" id="MSN-91-wRX"/>
<constraint firstItem="jsy-Gq-nsL" firstAttribute="centerY" secondItem="mDt-3d-EKK" secondAttribute="centerY" id="wDu-5s-hWc"/>
Expand All @@ -41,8 +41,7 @@
</connections>
</view>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="mDt-3d-EKK" firstAttribute="leading" secondItem="8ae-zI-9Zi" secondAttribute="leading" id="4uP-Lv-FZV"/>
<constraint firstAttribute="trailing" secondItem="mDt-3d-EKK" secondAttribute="trailing" id="JHG-fs-qtm"/>
Expand Down
Loading