这里发生了一些奇怪的事情。我有一个tableview,每行都有一个分段控件。这意味着,只需要一直选择一个分段控件。点击一个'控制项',就会推送一个segue。
如果我经常选择不同分段控件的项目,则没有任何进展,我的代码完美无缺。当我从同一个分段控件中选择一个不同的项目时,我有这个错误:
嵌套推送动画可能导致导航栏损坏 在意外状态下完成导航过渡。导航栏子视图树可能已损坏。 对于开始/结束外观转换的不平衡调用。
这是我的代码:
@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
答案 0 :(得分:0)
为什么要延迟goSegue
方法? <{1}}过去之前多次点击该项会带来麻烦。
我会改变:
afterDelay
为:
[self performSelector:@selector(goSegue) withObject:nil afterDelay:0.35];