Ios 尝试在自定义视图上添加集合视图时发生崩溃

Ios 尝试在自定义视图上添加集合视图时发生崩溃,ios,ios7,ios5,ios8,Ios,Ios7,Ios5,Ios8,当我试图在ios8中的自定义视图上添加集合视图时,我遇到了崩溃,而同一代码正在使用ios7 UINib *customNib = [UINib nibWithNibName:@"MYVIEW" bundle:nil]; MYVIEW *recentView = [[customNib instantiateWithOwner:self options:nil] objectAtIndex:0]; CGRect rect = recentView.frame; rect.origin

当我试图在ios8中的自定义视图上添加集合视图时,我遇到了崩溃,而同一代码正在使用ios7

  UINib *customNib = [UINib nibWithNibName:@"MYVIEW" bundle:nil];
  MYVIEW *recentView = [[customNib instantiateWithOwner:self options:nil] objectAtIndex:0];

 CGRect rect = recentView.frame;
 rect.origin.y = CGRectGetMaxY(collectionViewCampaign.frame)-50;
 [recentView setFrame:rect];
 [self.scrollViewRoot addSubview:recentView];
 [recentView addCollectionView];
 [recentView reloadCollection];
在MYVIEW类中

- (void)addCollectionView
{
  flowLayOut = [[UICollectionViewFlowLayout alloc] init];
[flowLayOut setItemSize:CGSizeMake(200, 320)];
[flowLayOut setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[flowLayOut setMinimumInteritemSpacing:0];
[flowLayOut setMinimumLineSpacing:5];
[flowLayOut setHeaderReferenceSize:CGSizeMake(0.0f, 20.0f)];
[flowLayOut setFooterReferenceSize:CGSizeMake(0.0f, 20.0f)];
[flowLayOut setSectionInset:UIEdgeInsetsMake(0, 20, 0, 20)];


collectionViewCampaign = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 410) collectionViewLayout:flowLayOut];
[collectionViewCampaign setDataSource:self];
[collectionViewCampaign setDelegate:self];
[collectionViewCampaign setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[collectionViewCampaign setBackgroundColor:[UIColor clearColor]];
[collectionViewCampaign setShowsHorizontalScrollIndicator:NO];
[collectionViewCampaign setShowsVerticalScrollIndicator:NO];
[self addSubview:collectionViewCampaign];
[collectionViewCampaign registerNib:[UINib nibWithNibName:@"MYCollectionCell" bundle:nil] forCellWithReuseIdentifier:kCellIdentifire];
}
我得到了下面这个崩溃
如果我删除下面的行,就不会发生碰撞

   [self addSubview:collectionViewCampaign];



Thread 1Queue : com.apple.main-thread (serial) 
#0  0x03d769f0 in CFArrayGetValueAtIndex () 
#1  0x0434be03 in TCharStream::CopyBreakIterator(__CFString const*) () 
#2  0x0434bbb6 in TCharStream::FindLineBreak(CFRange, bool, __CFString const*) const () 
#3  0x042da7f9 in TTypesetter::SuggestLineBreak(std::__1::tuple<TLine const*, TCharStream      const*, void const* (*)(__CTRun const*, __CFString const*, void*), void*,   std::__1::shared_ptr<TBidiLevelsProvider>*, unsigned int, unsigned char> const&, long, double,   double, std::__1::function<unsigned char (long)>) () 
#4  0x042da4fb in TTypesetter::SuggestLineBreak(TLine const&, long, double, double) () 
#5  0x042da160 in CTLineSuggestLineBreakWithOffset () 
#6  0x08ccab20 in __NSStringDrawingEngine () 
#7  0x08cc6172 in -[NSString(NSExtendedStringDrawing)   boundingRectWithSize:options:attributes:context:] () 

#8  0x0279addd in -[UILabel _drawTextInRect:baselineCalculationOnly:] () 
#9  0x02799b39 in -[UILabel drawTextInRect:] () 
#10 0x0279bf90 in -[UILabel drawRect:] () 
#11 0x0261edb5 in -[UIView(CALayerDelegate) drawLayer:inContext:] () 
#12 0x015d3659 in -[CALayer drawInContext:] () 
#13 0x015d358f in backing_callback(CGContext*, void*) () 
#14 0x014bb0a8 in CABackingStoreUpdate_ () 
#15 0x015d3527 in ___ZN2CA5Layer8display_Ev_block_invoke () 
#16 0x01607ef4 in x_blame_allocations () 
#17 0x015d338d in CA::Layer::display_() () 
#18 0x015d35de in -[CALayer _display] () 
#19 0x015d2d4e in CA::Layer::display() () 
#20 0x015d35b8 in -[CALayer display] () 
#21 0x015c77ca in CA::Layer::display_if_needed(CA::Transaction*) () 
#22 0x015c7850 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) () 
#23 0x01528b1e in CA::Context::commit_transaction(CA::Transaction*) () 
#24 0x01529ee4 in CA::Transaction::commit() () 
#25 0x015ececc in +[CATransaction flush] () 
#26 0x025c178d in _afterCACommitHandler () 
#27 0x03dc7b0e in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ () 
#28 0x03dc7a50 in __CFRunLoopDoObservers () 
#29 0x03dbc30a in __CFRunLoopRun () 
#30 0x03dbbb7b in CFRunLoopRunSpecific () 
#31 0x03dbb9ab in CFRunLoopRunInMode () 
#32 0x05c8d500 in GSEventRunModal () 
#33 0x05c8d33d in GSEventRun () 
#34 0x0259adee in UIApplicationMain () 
#35 0x001383cd in main at /...../main.m:16 
#36 0x063a6ac5 in start ()
[自添加子视图:collectionViewCampaign];
线程1队列:com.apple.main-Thread(串行)
#CFArrayGetValueAtIndex()中的0 0x03d769f0
#TCharStream::CopyBreakIterator(uu CFString const*)()中的1 0x0434be03
#TCharStream中的2 0x0434bbb6::FindLineBreak(CFRange,bool,u CFString const*)const()
#TTypesetter::SuggestLineBreak中的3 0x042da7f9(标准:元组常量,长,双精度,双精度,标准:函数)()
#TTypesetter中的4 0x042da4fb::SuggestLineBreak(TLine const&,long,double,double)()
#CTLineSuggestLineBreakWithOffset()中的5 0x042da160
#6 0x08ccab20英寸螺纹拉丝机()
#7 0x08cc6172 in-[NSString(NSExtendedStringDrawing)boundingRectWithSize:选项:属性:上下文:]()
#8 0x0279加载项-[UILabel\u drawTextInRect:baselineCalculationOnly:()
#9 0x02799b39英寸-[UILabel drawTextInRect:]()
#10 0x0279bf90英寸-[UILabel drawRect:]()
#11 0x0261edb5 in-[UIView(CALayerDelegate)绘图层:inContext:()
#12 0x015d3659英寸-[CALayer drawInContext:]()
#13 0x015d358f在backing_回调中(CGContext*,void*)()
#14 0x014bb0a8机柜中的存储更新
#15 0x015d3527英寸Zn2Ca5层8显示Ev块调用()
#x_分配中的16 0x01607ef4()
#CA::Layer::display_389;()中的17 0x015d338d()
#18 0x015d35de in-[CALayer(U)显示]()
#19 CA::Layer::display()中的0x015d2d4e()
#20 0x015d35b8英寸-[CALayer显示器]()
#21 0x015c77ca位于CA::Layer::如果需要显示(CA::Transaction*)()
#22 0x015c7850位于CA::Layer::layout和(如果需要)显示(CA::Transaction*)()
#23 0x01528b1e位于CA::Context::commit_事务(CA::transaction*)()
#CA::Transaction::commit()中的24 0x01529ee4()
#25 0x015 ECECC输入+[CATTransaction冲洗]()
#26 0x025c178d英寸,安装在控制台后()
#27 0x03dc7b0e in uu CFRUNLOOP u正在调用u OUT u到u观察器u回调函数u()
#28 0x03dc7a50英寸\uu cfrunloopdoobserver()
#29 0x03dbc30a在\uuuu CFRunLoopRun()中
#CFRunLoopRunSpecific()中的30 0x03dbbb7b
#CFRunLoopRunInMode()中的31 0x03dbb9ab
#GSEventRunModal()中的32 0x05c8d500
#GSEventRun()中的33 0x05c8d33d
#UIApplicationMain中的34 0x0259adee()
#35 0x001383cd位于/…../main.m:16处的干管中
#36 0x063a6ac5处于启动状态()
请帮忙


提前谢谢。

您能添加代码吗?您好@Roma我添加了代码本身请检查您是否在viewDidLoad中添加了addSubview?您能添加崩溃错误吗?除了崩溃日志,它可能很有用吗?是的,我正在添加到viewDidLoad中