Попробуйте
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.definesPresentationContext = YES;
}
- (void)viewDidDisappear:(BOOL)animated {
self.definesPresentationContext = NO;
[super viewDidDisappear:animated];
}
, он отлично работает для меня, но не уверен, что это хорошее решение или нет?
Этот статья глубже изучает проблему и возможные обходные решения. Концентратор вопроса - то, что календарная реализация.NET, кажется, искренне не реализует стандарт ISO
По моему опыту, продемонстрированное поведение является типичным поведением, называя частичную заключительную неделю неделей 53. Это может быть то, потому что все значительное воздействие, которое я имел к недельным числам, было связано с учетом конца календарного года для создания отчетов о целях, и IRS (или налоговая инспекция по Вашему выбору) полагает, что календарный год заканчивается 31 декабря, не прошлая целая неделя года.
@Conrad корректен. Реализация.NET DateTime и GregorianCalendar не реализует/следует полную спецификацию ISO 8601. Однако они спецификация чрезвычайно детализированы и нетривиальны для реализации полностью, по крайней мере, для стороны парсинга вещей.
еще Некоторая информация доступна на следующих сайтах:
Просто помещенный:
неделя А определяется ее числом в данном году и начинается с понедельника. Первая неделя года является той, которая включает первый четверг или эквивалентно тот, который включает 4 января.
Вот часть кода, который я использую для того, чтобы правильно обработать даты ISO 8601:
#region FirstWeekOfYear
/// <summary>
/// Gets the first week of the year.
/// </summary>
/// <param name="year">The year to retrieve the first week of.</param>
/// <returns>A <see cref="DateTime"/>representing the start of the first
/// week of the year.</returns>
/// <remarks>
/// Week 01 of a year is per definition the first week that has the Thursday
/// in this year, which is equivalent to the week that contains the fourth
/// day of January. In other words, the first week of a new year is the week
/// that has the majority of its days in the new year. Week 01 might also
/// contain days from the previous year and the week before week 01 of a year
/// is the last week (52 or 53) of the previous year even if it contains days
/// from the new year.
/// A week starts with Monday (day 1) and ends with Sunday (day 7).
/// </remarks>
private static DateTime FirstWeekOfYear(int year)
{
int dayNumber;
// Get the date that represents the fourth day of January for the given year.
DateTime date = new DateTime(year, 1, 4, 0, 0, 0, DateTimeKind.Utc);
// A week starts with Monday (day 1) and ends with Sunday (day 7).
// Since DayOfWeek.Sunday = 0, translate it to 7. All of the other values
// are correct since DayOfWeek.Monday = 1.
if (date.DayOfWeek == DayOfWeek.Sunday)
{
dayNumber = 7;
}
else
{
dayNumber = (int)date.DayOfWeek;
}
// Since the week starts with Monday, figure out what day that
// Monday falls on.
return date.AddDays(1 - dayNumber);
}
#endregion
#region GetIsoDate
/// <summary>
/// Gets the ISO date for the specified <see cref="DateTime"/>.
/// </summary>
/// <param name="date">The <see cref="DateTime"/> for which the ISO date
/// should be calculated.</param>
/// <returns>An <see cref="Int32"/> representing the ISO date.</returns>
private static int GetIsoDate(DateTime date)
{
DateTime firstWeek;
int year = date.Year;
// If we are near the end of the year, then we need to calculate
// what next year's first week should be.
if (date >= new DateTime(year, 12, 29))
{
if (date == DateTime.MaxValue)
{
firstWeek = FirstWeekOfYear(year);
}
else
{
firstWeek = FirstWeekOfYear(year + 1);
}
// If the current date is less than next years first week, then
// we are still in the last month of the current year; otherwise
// change to next year.
if (date < firstWeek)
{
firstWeek = FirstWeekOfYear(year);
}
else
{
year++;
}
}
else
{
// We aren't near the end of the year, so make sure
// we're not near the beginning.
firstWeek = FirstWeekOfYear(year);
// If the current date is less than the current years
// first week, then we are in the last month of the
// previous year.
if (date < firstWeek)
{
if (date == DateTime.MinValue)
{
firstWeek = FirstWeekOfYear(year);
}
else
{
firstWeek = FirstWeekOfYear(--year);
}
}
}
// return the ISO date as a numeric value, so it makes it
// easier to get the year and the week.
return (year * 100) + ((date - firstWeek).Days / 7 + 1);
}
#endregion
#region Week
/// <summary>
/// Gets the week component of the date represented by this instance.
/// </summary>
/// <value>The week, between 1 and 53.</value>
public int Week
{
get
{
return this.isoDate % 100;
}
}
#endregion
#region Year
/// <summary>
/// Gets the year component of the date represented by this instance.
/// </summary>
/// <value>The year, between 1 and 9999.</value>
public int Year
{
get
{
return this.isoDate / 100;
}
}
#endregion
Недельные числа отличаются от страны к стране и должны зависеть от Вашей локали/региональных настроек, если я не совсем неправ.
Редактирование: Википедия поддерживает мое неопределенное воспоминание, что эти числа отличаются на основе страны: http://en.wikipedia.org/wiki/Week_number#Week_number
я ожидал бы, что респектабельная платформа повинуется СТРАНЕ, выбранной в Вашем локальном времени выполнения.
Как работа вокруг, Вы могли сказать, что недельное число является модификацией WeekNumber 52. Я полагаю, что это работало бы на случаи, которые Вы описываете.
Как обходное решение, почему бы не использовать FirstFourDayWeek
, но добавьте:
if ( weekNumber > 52 )
weekNumber = 1;