0

每当我在我的 iphone 应用程序中点击 segmentedControl 时,我都会遇到 EXC_BAD_ACCESS。

我正在使用一个名为 PPiFlatSegmentedControl ( https://github.com/pepibumur/PPiFlatSegmentedControl ) 的 OSS 库。这是我初始化段的代码:

- (void)setupSegmentedControl {
  // open source library - PPiFlatSegmentedControl
  PPiFlatSegmentedControl *segmentedControl = [[PPiFlatSegmentedControl alloc] initWithFrame:CGRectMake(0, 42, 320, 40) items:@[
                                              @{@"text":@"ALL"},
                                              @{@"text":@"COMPLETED"},
                                              @{@"text":@"UNCOMPLETED"}] iconPosition:IconPositionRight andSelectionBlock:^(NSUInteger segmentIndex) {
                                              switch (segmentIndex) {
                                                  case 0:
                                                       // All
                                                       //[self enableFilters];
                                                       [tasks addObjectsFromArray:[[CoreDataManager sharedInstance] fetchTaskList]];
                                                       break;
                                                  case 1:
                                                        // Complete
                                                        [tasks addObjectsFromArray:[[CoreDataManager sharedInstance] fetchTasksByCompletion:YES]];
                                                        break;
                                                  case 2:
                                                        // Uncompleted
                                                        [tasks addObjectsFromArray:[[CoreDataManager sharedInstance] fetchTasksByCompletion:NO]];
                                                        break;
                                                  default:
                                                  break;
                                               }


                                              }];

  segmentedControl.color=[UIColor colorWithRed:45.0f/255.0 green:203.0f/255.0 blue:116.0f/255.0 alpha:1];
  segmentedControl.borderWidth=0.5;
  segmentedControl.borderColor=[UIColor darkGrayColor];
  segmentedControl.selectedColor=[UIColor colorWithRed:36.0f/255.0 green:190.0f/255.0 blue:104.0f/255.0 alpha:1];
  segmentedControl.textAttributes=@{NSFontAttributeName:[UIFont systemFontOfSize:13],
                             NSForegroundColorAttributeName:[UIColor whiteColor]};
  segmentedControl.selectedTextAttributes=@{NSFontAttributeName:[UIFont systemFontOfSize:13],
                                     NSForegroundColorAttributeName:[UIColor whiteColor]};
  [self.view addSubview:segmentedControl];

所以,每当我点击其中一个单元格/按钮时,我都会收到该错误。请记住,我的项目目前没有 ARC——所以我真的觉得我管理内存不正确。如果您需要更多信息或其他任何信息 - 请告诉我!

-马特

4

0 回答 0