Question

Something weird going on here. I have a tableview, and in each row there is a segmentedcontrol. The meaning of this is, that there only has to be one segmented control selected at all time. On a click of a 'control item', there is a segue that is pushed.

If I constantly select items of different segmented controls, there is nothing going on, my code works perfectly. When i select an different item from the same segmented control, i have this error:

nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. Unbalanced calls to begin/end appearance transitions for .

This is my code:

@interface PerformancesController ()
{
    GFilm* currentFilm;
    GTimePerformance* chosenTimePerf;
}
@end

@implementation PerformancesController



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
return [currentFilm.dayList count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView     dequeueReusableCellWithIdentifier:@"myCustomCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCustomCell"];
    }


CAGradientLayer *bgLayer = [BackgroundLayer blackGradient];
bgLayer.frame = cell.bounds;
[cell.contentView.layer addSublayer:bgLayer];
cell.contentView.backgroundColor = [UIColor darkGrayColor];
cell.textLabel.textAlignment = UITextAlignmentLeft;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

if(indexPath.row == 0)
{
    CGRect rctStreep = cell.bounds;
    rctStreep.origin.y = rctStreep.origin.y+1;
    rctStreep.size.height = 1;
    UIImageView* imgv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"streep.png"]];
    imgv.backgroundColor = [UIColor blackColor];
    imgv.frame = rctStreep;
    [cell.contentView addSubview:imgv];


}

CGRect rctStreep = cell.bounds;
rctStreep.origin.y = rctStreep.origin.y + rctStreep.size.height;
rctStreep.size.height = 1;
UIImageView* imgv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"streep.png"]];
imgv.backgroundColor = [UIColor blackColor];
imgv.frame = rctStreep;
[cell.contentView addSubview:imgv];
imgv = nil;

NSArray* dayList = currentFilm.dayList;
GDay* d = (GDay*)[dayList objectAtIndex:indexPath.row];


CGRect rctDayLabel = CGRectMake(15, 7, 80, 30);
UILabel* lblDay = [[UILabel alloc]initWithFrame:rctDayLabel];
lblDay.textColor = [GColor yellowAccentColor];
NSDate* date = d.date;


if([date isToday])
{
    lblDay.text = @"Vandaag";
}
else if([date isTomorrow])
{
    lblDay.text = @"Morgen";
}
else
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd/MM"];
    lblDay.text = [formatter stringFromDate:date];
}

[cell.contentView addSubview:lblDay];

NSMutableArray* itemArray = [[NSMutableArray alloc]init];
int i = 0;
GTimePerformance* prevChosen = currentFilm.displayPerformance;
int gekozen = -1;

for(i; i < [d.timeIdList count]; i++)
{

    GTimePerformance* per = [d.timeIdList objectAtIndex:i];
    if([per.performanceId isEqualToString:prevChosen.performanceId])
    {
        gekozen = i;
    }

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm"];
    [itemArray addObject:[formatter stringFromDate:per.performanceTime]];
}



float itemWidth = (cell.frame.size.width - (2* rctDayLabel.origin.x))/4;

MySegmentedControl *segmentedControl = [[MySegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(rctDayLabel.origin.x, cell.frame.size.height - rctDayLabel.origin.y - 30, itemWidth*[d.timeIdList count] , 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.tintColor = [GColor filterComponentColor];
if(gekozen >= 0)
{
    [segmentedControl setSelectedSegmentIndex:gekozen];
}
[segmentedControl addTarget:self
                     action:@selector(clickedPerformance:)
           forControlEvents:UIControlEventValueChanged];
UIFont *font = [UIFont systemFontOfSize:10.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                       forKey:NSFontAttributeName];
[segmentedControl setTitleTextAttributes:attributes
                                forState:UIControlStateNormal];
segmentedControl.tag = 200 + indexPath.row;
[cell.contentView addSubview:segmentedControl];

return cell;

}


-(void)clickedPerformance:(id)sender
 {

    UISegmentedControl *segment = (UISegmentedControl*)sender;

   if(segment.selectedSegmentIndex != -1)
   {
       int tag = segment.tag;
       int i = 0;
       for(i; i < [currentFilm.dayList count]; i++)
       {
           int diffTag = i + 200;
           if(diffTag != tag)
           {
               UISegmentedControl* sControl = (UISegmentedControl*)[self.view viewWithTag:diffTag];
           [sControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
       }
   }

   NSLog(@"lalala");
   GDay* day = (GDay*)[currentFilm.dayList objectAtIndex:tag-200];
   chosenTimePerf = [day.timeIdList objectAtIndex:segment.selectedSegmentIndex];
   NSLog(chosenTimePerf.performanceId);
   [self performSelector:@selector(goSegue) withObject:nil afterDelay:0.35];

  }
}
-(void)goSegue
{
    [self performSegueWithIdentifier:@"pushPrices" sender:self];
}


// In a storyboard-based application, you will often want to do a little preparation     before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     NSString * segueName = segue.identifier;
     if ([segueName isEqualToString: @"pushPrices"]) {
     PricesController* pc = (PricesController*)[segue destinationViewController];
    [pc setMovie:currentFilm andPerformance:chosenTimePerf];
}

}


@end
Was it helpful?

Solution

Why do you delay the goSegue method? hitting the item multiple times before afterDelay has elapsed will cause trouble.

I would change:

[self performSelector:@selector(goSegue) withObject:nil afterDelay:0.35];

to:

[self goSegue];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top