Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
8fcc9797
Commit
8fcc9797
authored
Jun 29, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix crash in TodayDayTimesCell.
parent
f39d9614
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
25 deletions
+25
-25
1Weather/UI/View controllers/Today/Cells/TodayDayTimesCell/TodayDayTimesCell.swift
+25
-25
No files found.
1Weather/UI/View controllers/Today/Cells/TodayDayTimesCell/TodayDayTimesCell.swift
View file @
8fcc9797
...
...
@@ -55,40 +55,40 @@ class TodayDayTimesCell: UITableViewCell {
public
func
configure
(
with
location
:
Location
)
{
let
maxNumberOfItems
=
4
guard
!
location
.
dayTimeForecast
.
isEmpty
else
{
return
}
var
validDayTimeWeather
=
[
DayTimeWeather
]()
for
index
in
0
..<
location
.
dayTimeForecast
.
count
{
if
location
.
dayTimeForecast
[
index
]
.
date
>=
Date
()
{
validDayTimeWeather
.
append
(
location
.
dayTimeForecast
[
index
])
}
}
if
validDayTimeWeather
.
isEmpty
{
return
}
if
stackView
.
arrangedSubviews
.
isEmpty
{
for
index
in
0
..<
maxNumberOfItems
{
let
view
=
DayTimeView
(
dayTimeWeather
:
validDayTimeWeather
[
index
],
withSeparator
:
index
!=
maxNumberOfItems
-
1
)
stackView
.
addArrangedSubview
(
view
)
for
dayTimeWeather
:
DayTimeWeather
in
location
.
dayTimeForecast
{
if
dayTimeWeather
.
date
>=
Date
()
{
validDayTimeWeather
.
append
(
dayTimeWeather
)
if
validDayTimeWeather
.
count
==
maxNumberOfItems
{
break
}
}
stackView
.
layoutIfNeeded
()
return
}
if
stackView
.
arrangedSubviews
.
count
==
maxNumberOfItems
{
for
(
index
,
arrangedSubview
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
var
currentValidWeatherIndex
=
0
for
(
index
,
arrangedSubview
)
in
stackView
.
arrangedSubviews
.
enumerated
()
{
// Configure existing views
if
currentValidWeatherIndex
<
validDayTimeWeather
.
count
{
guard
let
dayTimeView
=
arrangedSubview
as?
DayTimeView
else
{
continue
}
dayTimeView
.
configure
(
with
:
validDayTimeWeather
[
index
])
dayTimeView
.
configure
(
with
:
validDayTimeWeather
[
currentValidWeatherIndex
])
currentValidWeatherIndex
+=
1
}
else
{
// Remove excessive views
arrangedSubview
.
removeFromSuperview
()
}
}
// Add new views if needed.
while
currentValidWeatherIndex
<
validDayTimeWeather
.
count
{
let
isLastItem
=
currentValidWeatherIndex
==
validDayTimeWeather
.
count
-
1
let
view
=
DayTimeView
(
dayTimeWeather
:
validDayTimeWeather
[
currentValidWeatherIndex
],
withSeparator
:
!
isLastItem
)
stackView
.
addArrangedSubview
(
view
)
currentValidWeatherIndex
+=
1
}
stackView
.
layoutIfNeeded
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment