Отображение таблицы действий приводит к ошибкам контекста CGContext

Я использую Actionsheet для отображения списков данных для выбора пользователем. Проблема заключается в том, что показ списка действий с использованием [self.actionSheet showInView:self.view]; вызывает несколько ошибок CGContext. Тот же код хорошо работал в iOS 6.

Код:

self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                             delegate:nil
                                    cancelButtonTitle:nil
                               destructiveButtonTitle:nil
                                    otherButtonTitles:nil];
[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];

CGRect tableFrame = CGRectMake(0, 40, 320, 214);
self.tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.actionSheet addSubview:self.tableView];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.tintColor = [UIColor redColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:closeButton];

[self.actionSheet showFromView:self.view];

[UIView beginAnimations:nil context:nil];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[UIView commitAnimations];

Ошибки:

CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextSetFlatness: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextAddPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextDrawPath: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

Обновить:

Обходной путь для установки cancelButtonTitle равным @"" приводит к этой проблеме пользовательского интерфейса для меня:

последо

Исходный код был получен из другого ответа stackru, см. /questions/34175101/dobavit-uipickerview-i-knopku-v-liste-dejstvij-kak/34175110#34175110.

3 ответа

Решение

Я считаю, что ответ здесь заключается в том, что UIActionSheet не предназначен для использования таким образом, и в результате могут иметь такие побочные эффекты, как эти. Из документации Apple ActionSheet"UIActionSheet не предназначен для создания подклассов, и вы не должны добавлять представления в его иерархию".

Хотя в iOS 6 это не создавало проблем для меня, в iOS 7 что-то явно изменилось, и я больше склоняюсь к тому, чтобы пойти другим путем, чем пытаться сделать что-то, что противоречит документации. Обратите внимание, что обходной путь может заключаться в передаче @"" для cancelButtonTitle, а не в nil, но это вызывает другие проблемы с пользовательским интерфейсом и может быть не одобрено Apple.

Альтернативные решения:

  1. Создайте свой собственный вид и представьте его модально - я сделал простой пример проекта, показывающий один из способов сделать это.
  2. https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets (обновления для iOS 7 пока нет)

Кайл, Какие еще проблемы с пользовательским интерфейсом у вас возникли после использования @""?

После того, как я использовал следующий код, он отлично работает для меня. Я не использую tableview, хотя, я использую pickerview как подпредставление.

   self.startSheet=[[UIActionSheet alloc]initWithTitle:nil
                                           delegate:nil
                                  cancelButtonTitle:@""
                             destructiveButtonTitle:nil
                                  otherButtonTitles:nil];

Вот ответ, который я дал на похожий вопрос, который хорошо работает

self.actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                               delegate:nil
                                      cancelButtonTitle:nil
                                 destructiveButtonTitle:nil
                                      otherButtonTitles:nil];

Однако это может испортить графику / рисунок в верхней части листа действий, поэтому, если у вас еще нет фона, добавьте этот код, чтобы получить внешний вид листа действий по умолчанию.

UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
background.backgroundColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1];
[self.actionSheet addSubview:background];

затем добавьте все, что вы хотите в свой список действий.

Другие вопросы по тегам