Skip to content

Commit db53565

Browse files
Borinschi IvanBorinschi Ivan
authored andcommitted
Bug fixing.
1 parent c653a10 commit db53565

9 files changed

Lines changed: 171 additions & 35 deletions

File tree

Examples/ImoTableViewExample/ImoTableViewExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
41BDE4B01F0627E60029E4C2 /* ScrollCatchExampleVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41BDE4AF1F0627E60029E4C2 /* ScrollCatchExampleVC.swift */; };
4242
41C677C81EF136E2003AD834 /* Fakery.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 41C677C71EF136E2003AD834 /* Fakery.framework */; };
4343
41C677CA1EF136E5003AD834 /* Fakery.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 41C677C71EF136E2003AD834 /* Fakery.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
44+
41C745BD1FB44F1D00E56651 /* AnimatedInsertMultipleSections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C745BC1FB44F1D00E56651 /* AnimatedInsertMultipleSections.swift */; };
4445
41DB85C51EE063D00099CFC4 /* BasicsActionsExampleVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41DB85C41EE063D00099CFC4 /* BasicsActionsExampleVC.swift */; };
4546
41DB85C71EE067B10099CFC4 /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41DB85C61EE067B10099CFC4 /* UIViewControllerExtension.swift */; };
4647
/* End PBXBuildFile section */
@@ -121,6 +122,7 @@
121122
4187E3801EC354ED0030218F /* BasicsExampleVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicsExampleVC.swift; sourceTree = "<group>"; };
122123
41BDE4AF1F0627E60029E4C2 /* ScrollCatchExampleVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollCatchExampleVC.swift; sourceTree = "<group>"; };
123124
41C677C71EF136E2003AD834 /* Fakery.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Fakery.framework; sourceTree = "<group>"; };
125+
41C745BC1FB44F1D00E56651 /* AnimatedInsertMultipleSections.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatedInsertMultipleSections.swift; sourceTree = "<group>"; };
124126
41DB85BB1EE0630C0099CFC4 /* ImoTableView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ImoTableView.xcodeproj; path = ../../ImoTableView/ImoTableView.xcodeproj; sourceTree = "<group>"; };
125127
41DB85C41EE063D00099CFC4 /* BasicsActionsExampleVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicsActionsExampleVC.swift; sourceTree = "<group>"; };
126128
41DB85C61EE067B10099CFC4 /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtension.swift; sourceTree = "<group>"; };
@@ -229,6 +231,7 @@
229231
4172BE9A1EC356BF00E33F64 /* MultipleSectionsExampleVC.swift */,
230232
4187E3441EC2FD440030218F /* AutomaticScrollAdjustExampleVC.swift */,
231233
4172BEA61EC4533E00E33F64 /* AnimatedAddCellsExample.swift */,
234+
41C745BC1FB44F1D00E56651 /* AnimatedInsertMultipleSections.swift */,
232235
415016881F755B1A0032AC29 /* UpdateChangedSectionsExample.swift */,
233236
415016D51F79454D0032AC29 /* AddDeleteIfExistExample.swift */,
234237
4172BEAC1EC4593200E33F64 /* AnimatedDeleteCellsExample.swift */,
@@ -417,6 +420,7 @@
417420
4172BEBD1EC495F100E33F64 /* SpaceCell.swift in Sources */,
418421
411410E71DF55ECD00E737BA /* AppDelegate.swift in Sources */,
419422
4187E3491EC314A80030218F /* BaseViewController.swift in Sources */,
423+
41C745BD1FB44F1D00E56651 /* AnimatedInsertMultipleSections.swift in Sources */,
420424
4187E3471EC308150030218F /* Explorable.swift in Sources */,
421425
4172BEAD1EC4593200E33F64 /* AnimatedDeleteCellsExample.swift in Sources */,
422426
);
@@ -563,6 +567,7 @@
563567
"$(PROJECT_DIR)",
564568
);
565569
INFOPLIST_FILE = ImoTableViewExample/Info.plist;
570+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
566571
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
567572
PRODUCT_BUNDLE_IDENTIFIER = Imodeveloperlab.ImoTableViewExample;
568573
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -581,6 +586,7 @@
581586
"$(PROJECT_DIR)",
582587
);
583588
INFOPLIST_FILE = ImoTableViewExample/Info.plist;
589+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
584590
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
585591
PRODUCT_BUNDLE_IDENTIFIER = Imodeveloperlab.ImoTableViewExample;
586592
PRODUCT_NAME = "$(TARGET_NAME)";
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// AutomaticScrollAdjustExampleVC.swift
3+
// ImoTableViewExample
4+
//
5+
// Created by Borinschi Ivan on 5/10/17.
6+
// Copyright © 2017 Imodeveloperlab. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
import ImoTableView
12+
import Fakery
13+
14+
class AnimatedInsertMultipleSections: BaseViewController {
15+
16+
let faker = Faker.init()
17+
18+
let mainSection = ImoTableViewSection()
19+
var table: ImoTableView!
20+
21+
override func exploreTitle() -> String {
22+
return "Animated add Multiple sections"
23+
}
24+
25+
override func viewDidLoad() {
26+
27+
super.viewDidLoad()
28+
29+
//HIDE THE KAYBOARD WHEN TAPPED ARROUND
30+
self.hideKeyboardWhenTappedAround()
31+
32+
//TABLE
33+
self.table = ImoTableView(on: self.view)
34+
35+
//ADD ONE CELL ACTION
36+
let addSource = ActionCellSource(title: "Insert sections")
37+
mainSection.add(addSource, target: self, #selector(insertNewSections))
38+
39+
//ADD SECTIONS TO TABLE
40+
table.add(section: mainSection)
41+
}
42+
43+
override func viewDidAppear(_ animated: Bool) {
44+
45+
super.viewDidAppear(animated)
46+
47+
insertNewSections()
48+
49+
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
50+
self.insertNewSections()
51+
}
52+
}
53+
54+
func insertNewSections() {
55+
56+
var sections = [ImoTableViewSection]()
57+
58+
for i in 0...5 {
59+
60+
let section = ImoTableViewSection()
61+
section.headerHeight = 25
62+
section.estimatedHeaderHeight = 0
63+
section.estimatedFooterHeight = 0
64+
section.footerHeight = 0
65+
66+
section.headerTitle = "Header \(i)"
67+
section.add(sources: getMultipleCells())
68+
sections.append(section)
69+
}
70+
71+
table.add(sections: sections, animated: true, animation: .none)
72+
}
73+
74+
func getMultipleCells() -> [TextCellSource] {
75+
76+
var sources: [TextCellSource] = []
77+
78+
for _ in 0...5 {
79+
let text = faker.lorem.sentence()
80+
sources.append(TextCellSource(text: text))
81+
}
82+
83+
return sources
84+
}
85+
}

Examples/ImoTableViewExample/ImoTableViewExample/AutomaticScrollAdjustExampleVC.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class AutomaticScrollAdjustExampleVC: BaseViewController {
2323

2424
super.viewDidLoad()
2525
self.hideKeyboardWhenTappedAround()
26-
let table = ImoTableView(on: self.view)
26+
let table = ImoTableView(on: self.view, insets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
27+
28+
table.tableView.contentInset = UIEdgeInsets(top: 100, left: 0, bottom: 60, right: 0)
29+
table.tableView.scrollIndicatorInsets = UIEdgeInsets(top: 100, left: 0, bottom: 60, right: 0)
2730

2831
table.adjustContentInsetsForKeyboard(true)
2932
let section = ImoTableViewSection()

Examples/ImoTableViewExample/ImoTableViewExample/UpdateChangedSectionsExample.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class UpdateChangedSectionsExample: BaseViewController {
5252
let updateChanged = ActionCellSource(title: "Update changed sections")
5353
mainSection.add(updateChanged, target: self, #selector(updateChangedSections))
5454

55+
let sequenceChangeAndUpdate = ActionCellSource(title: "Sequence Change And Update Sections")
56+
mainSection.add(sequenceChangeAndUpdate, target: self, #selector(sequenceChangeAndUpdateSections))
57+
5558
//ADD SECTIONS TO TABLE
5659
table.add(section: mainSection)
5760

@@ -105,5 +108,28 @@ class UpdateChangedSectionsExample: BaseViewController {
105108

106109
}
107110

111+
func sequenceChangeAndUpdateSections() {
112+
113+
table.updateChangedSections()
114+
115+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
116+
117+
self.addSourceInSecondSection()
118+
self.addSourceInSecondSection()
119+
self.table.updateChangedSections()
120+
}
121+
122+
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
123+
124+
125+
self.addSourceInThirdSection()
126+
self.addSourceInThirdSection()
127+
self.addSourceInThirdSection()
128+
self.table.updateChangedSections()
129+
130+
}
131+
132+
}
133+
108134

109135
}

Examples/ImoTableViewExample/ImoTableViewExample/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ViewController: UIViewController {
3737
explore.append(ScrollCatchExampleVC())
3838
explore.append(UpdateChangedSectionsExample())
3939
explore.append(AddDeleteIfExistExample())
40-
40+
explore.append(AnimatedInsertMultipleSections())
4141

4242
self.show(examples: explore)
4343
}

ImoTableView/ImoTableView/ImoTableView.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public final class ImoTableView : UIView, UITableViewDelegate, UITableViewDataSo
4040
//Estimated height for row
4141
var estimatedHeightForRow: CGFloat = 40
4242

43+
//Is keyboard on screeen
44+
var isKeyboardOnScreen: Bool = false
45+
4346
//This array hold all table sections
4447
var sections = [ImoTableViewSection]()
4548

@@ -249,13 +252,13 @@ public final class ImoTableView : UIView, UITableViewDelegate, UITableViewDataSo
249252
return UITableViewAutomaticDimension
250253
}
251254

252-
public func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
253-
254-
if let section = sectionForIndex(index: section) {
255-
return section.estimatedHeaderHeight
256-
}
257-
return 0
258-
}
255+
// public func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
256+
//
257+
// if let section = sectionForIndex(index: section) {
258+
// return section.estimatedHeaderHeight
259+
// }
260+
// return 0
261+
// }
259262

260263
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
261264

@@ -286,13 +289,13 @@ public final class ImoTableView : UIView, UITableViewDelegate, UITableViewDataSo
286289
return UITableViewAutomaticDimension
287290
}
288291

289-
public func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
290-
291-
if let section = sectionForIndex(index: section) {
292-
return section.estimatedFooterHeight
293-
}
294-
return 0
295-
}
292+
// public func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
293+
//
294+
// if let section = sectionForIndex(index: section) {
295+
// return section.estimatedFooterHeight
296+
// }
297+
// return 0
298+
// }
296299

297300
public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
298301

ImoTableView/ImoTableView/ImoTableViewExtension.swift

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ public extension ImoTableView {
6060

6161
storedContentInset = self.tableView.contentInset
6262
storedScrollIndicatorInsets = self.tableView.scrollIndicatorInsets
63+
64+
isKeyboardOnScreen = true
6365
adjustScroll(for: notification)
6466
}
6567

6668
/// Keyboard will hide notification
6769
///
6870
/// - Parameter notification: Notification
6971
func keyboardWillHide(_ notification: Notification) {
72+
73+
isKeyboardOnScreen = false
7074
adjustScroll(for: notification)
7175
}
7276

@@ -115,25 +119,32 @@ public extension ImoTableView {
115119
/// - Returns: UIEdgeInsets
116120
func insets(for keyboardFrame: CGRect) -> UIEdgeInsets {
117121

118-
guard let view = self.tableView.superview,
119-
let mainWindowView = mainWindowView() else {
120-
if let storedContentInset = self.storedContentInset {
121-
return storedContentInset
122-
} else {
123-
return self.tableView.contentInset
122+
if isKeyboardOnScreen {
123+
124+
guard let view = self.superview,
125+
let mainWindowView = mainWindowView() else {
126+
return self.tableView.contentInset
124127
}
128+
129+
let tableFrame = self.tableView.frame
130+
let convertedTableFrame = view.convert(tableFrame, to: view)
131+
let inset = keyboardFrame.intersection(convertedTableFrame).height
132+
let currentTableInsets = self.tableView.contentInset
133+
let topMargin = view.frame.size.height - (self.frame.size.height + self.frame.origin.y)
134+
let difference = mainWindowView.frame.size.height - self.frame.size.height - topMargin
135+
136+
let insetts = UIEdgeInsets(top: currentTableInsets.top,
137+
left: currentTableInsets.left,
138+
bottom: inset + difference,
139+
right: currentTableInsets.right)
140+
return insetts
125141
}
126142

127-
let tableFrame = self.tableView.frame
128-
let convertedTableFrame = view.convert(tableFrame, to: view)
129-
let inset = keyboardFrame.intersection(convertedTableFrame).height
130-
let currentTableInsets = self.tableView.contentInset
131-
let difference = mainWindowView.frame.size.height - view.frame.size.height
143+
if let storedContentInset = self.storedContentInset {
144+
return storedContentInset
145+
}
132146

133-
return UIEdgeInsets(top: currentTableInsets.top,
134-
left: currentTableInsets.left,
135-
bottom: inset + difference,
136-
right: currentTableInsets.right)
147+
return self.tableView.contentInset
137148
}
138149

139150
/// Get top view from window

ImoTableView/ImoTableView/ImoTableViewSectionsExtension.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public extension ImoTableView {
3838
animation: UITableViewRowAnimation = .fade) {
3939

4040
self.sections.append(contentsOf: sections)
41+
4142
if animated {
4243
animateInsertSections(sections, animation)
4344
}
@@ -206,7 +207,6 @@ public extension ImoTableView {
206207
return self.sections.index(of: section)
207208
}
208209

209-
210210
/// Index array of sections
211211
///
212212
/// - Parameter sections: Sections Array
@@ -229,7 +229,6 @@ public extension ImoTableView {
229229
return nil
230230
}
231231

232-
233232
/// Index array of sections
234233
///
235234
/// - Parameter sections: Sections Array
@@ -259,7 +258,6 @@ public extension ImoTableView {
259258
return nil
260259
}
261260

262-
263261
// MARK: - Animated updates
264262

265263
/// Animate insert section
@@ -303,7 +301,7 @@ public extension ImoTableView {
303301
///
304302
/// - Parameter sections: Array of sections
305303
/// - Returns: IndexSet
306-
func indexSetForSections(sections: [ImoTableViewSection]) -> IndexSet {
304+
public func indexSetForSections(sections: [ImoTableViewSection]) -> IndexSet {
307305

308306
var indexes: [Int] = []
309307
for section in sections {

ImoTableView/ImoTableView/ImoTableViewSourcesExtension.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ public extension ImoTableView {
176176
}
177177
}
178178

179+
for ip in indexes {
180+
print("\(ip.row) \(ip.section)")
181+
}
182+
179183
return indexes
180184
}
181185
}

0 commit comments

Comments
 (0)