Отображение таблиц действий вызывает недопустимые контекстные ошибки CGContext
Я использую таблицу действий для отображения списков данных для пользователя на выбор. Проблема в том, что показ таблицы действий с использованием [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.
Update:
Обходной путь для установки cancelButtonTitle для @"" приводит к этой проблеме интерфейса для меня:
![after]()
![before]()
Исходный код пришел из другого ответа stackoverflow, см. qaru.site/info/49534/....
Ответы
Ответ 1
Я считаю, что ответ здесь заключается в том, что UIActionSheet не предназначен для использования таким образом, и в результате могут иметь такие побочные эффекты. Из Документация Apple ActionSheet: "UIActionSheet не предназначен для подкласса, и вы не должны добавлять представления в свою иерархию".
Хотя это не вызывало проблем для меня в iOS 6, в iOS 7 явно изменилось, и я больше склоняюсь к тому, чтобы спуститься по другому маршруту, чем пытаться сделать что-то противоречащее документам. Обратите внимание, что обходным решением может быть передача @"" для cancelButtonTitle, а не nil, но это вызывает другие проблемы пользовательского интерфейса и может не одобряться Apple.
Альтернативные решения:
Ответ 2
Кайл, Что еще проблема с пользовательским интерфейсом, которую вы используете после использования @""?
После того, как я использовал следующий код, он отлично работает для меня. Я не использую tableview, хотя, я использую pickerview как subview.
self.startSheet=[[UIActionSheet alloc]initWithTitle:nil
delegate:nil
cancelButtonTitle:@""
destructiveButtonTitle:nil
otherButtonTitles:nil];
Ответ 3
Вот ответ, который я дал на аналогичном question, который хорошо работает
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];
затем добавьте все, что вы хотите, в свой собственный лист действий.