Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
enzevalos_iphone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
enzevalos
enzevalos_iphone
Commits
6c7af886
Commit
6c7af886
authored
5 years ago
by
lazarog98
Browse files
Options
Downloads
Patches
Plain Diff
Add delay when searching
parent
63da3385
No related branches found
No related tags found
1 merge request
!27
Resolve "Improve searching"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
enzevalos_iphone/InboxViewController.swift
+17
-3
17 additions, 3 deletions
enzevalos_iphone/InboxViewController.swift
with
17 additions
and
3 deletions
enzevalos_iphone/InboxViewController.swift
+
17
−
3
View file @
6c7af886
...
...
@@ -39,6 +39,7 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
}
}
}
var
searchBarTimer
:
Timer
?
@IBOutlet
weak
var
lastUpdateButton
:
UIBarButtonItem
!
var
lastUpdateLabel
=
UILabel
(
frame
:
CGRect
.
zero
)
...
...
@@ -248,7 +249,20 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
return
searchController
.
isActive
&&
!
searchBarIsEmpty
}
func
filterContentForSearchText
(
_
searchText
:
String
,
scope
:
Int
=
0
)
{
/// searches a given string with a delay so that the entire client doesn't lag if the inbox is very big
func
startSearch
(
searchText
:
String
,
scope
:
Int
=
0
)
{
if
#available
(
iOS
10.0
,
*
)
{
if
let
searchBarTimer
:
Timer
=
self
.
searchBarTimer
{
searchBarTimer
.
invalidate
()
}
self
.
searchBarTimer
=
Timer
.
scheduledTimer
(
withTimeInterval
:
1.0
,
repeats
:
false
,
block
:
{
_
in
self
.
filterContentForSearchText
(
searchText
,
scope
:
scope
)
})
}
}
private
func
filterContentForSearchText
(
_
searchText
:
String
,
scope
:
Int
=
0
)
{
var
records
=
[
KeyRecord
]()
if
scope
==
0
||
scope
==
3
{
records
+=
folder
.
records
.
filter
({
(
record
:
KeyRecord
)
->
Bool
in
...
...
@@ -286,13 +300,13 @@ extension InboxViewController: UISearchResultsUpdating {
// https://www.raywenderlich.com/157864/uisearchcontroller-tutorial-getting-started
func
updateSearchResults
(
for
searchController
:
UISearchController
)
{
filterContentForS
earchText
(
searchController
.
searchBar
.
text
!
,
scope
:
searchController
.
searchBar
.
selectedScopeButtonIndex
)
startSearch
(
s
earchText
:
searchController
.
searchBar
.
text
!
,
scope
:
searchController
.
searchBar
.
selectedScopeButtonIndex
)
}
}
extension
InboxViewController
:
UISearchBarDelegate
{
func
searchBar
(
_
searchBar
:
UISearchBar
,
selectedScopeButtonIndexDidChange
selectedScope
:
Int
)
{
filterContentForS
earchText
(
searchBar
.
text
!
,
scope
:
selectedScope
)
startSearch
(
s
earchText
:
searchBar
.
text
!
,
scope
:
selectedScope
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment