UICollectionView를 사용하여 간단한 메뉴를 표시하는 클래스를 만들려고 노력 중이지만 끝이없는 문제와 필자가 본 가장 이상한 오류 메시지가 있습니다.SIGABRT Error UICollectionView를 사용할 때
#import <UIKit/UIKit.h>
@interface Menu : UIViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView * menuView;
@property (nonatomic, strong) UIView * containerView;
@property (nonatomic, strong) NSArray * clocks;
- (NGCMenu*) initWithClockArray: (NSArray*) clockArray;
- (void) displayMenuInView: (UIView*) view;
- (void) clearMenu;
@end
Menu.m :
Menu.h : 여기
작동이 잘 지난주 코드입니다#import "Menu.h"
@implementation Menu
@synthesize menuView,containerView,clocks;
- (Menu*) initWithClockArray: (NSArray*) clockArray {
clocks=[[NSArray alloc] initWithArray: clockArray];
return self;
}
- (void) displayMenuInView: (UIView*) view {
CGRect menuFrame=CGRectMake(50, 50, 200, 500);
containerView=[[UIView alloc] initWithFrame: menuFrame];
UIScrollView * scrollView=[[UIScrollView alloc] initWithFrame:containerView.frame];
UICollectionViewFlowLayout * layout=[[UICollectionViewFlowLayout alloc] init];
menuView=[[UICollectionView alloc] initWithFrame:menuFrame collectionViewLayout:layout];
[menuView setDataSource:self];
[menuView setDelegate:self];
[menuView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
[scrollView addSubview:menuView];
[containerView addSubview:scrollView];
[view addSubview:containerView];
}
- (void) clearMenu {
[containerView removeFromSuperview];
}
- (NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
NSInteger i=(NSInteger) 30;
return i;
}
- (UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell * cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
NSString * labelText=[NSString stringWithFormat:@"%d",indexPath.row];
UILabel * label=[[UILabel alloc] initWithFrame:cell.frame];
[label setText:labelText];
[cell addSubview:label];
return cell;
}
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(50, 50);
}
@end
크립 틱 오류 메시지 :
Thread 1: signal SIGABRT
main.m, o에 표시됩니다. n은 UIApplicationMain
을 반환하는 행입니다.
추적 출력 :
2013-07-29 10:32:44.016 tyrionCollection2[2620:11303] -[__NSCFDictionary collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x886fed0
2013-07-29 10:32:44.018 tyrionCollection2[2620:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x886fed0'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x543b6f 0x543c0a 0x5454c4 0x51d7d4 0x53338a 0x533fa1 0x5303aa 0x543c9a 0x5442db 0x51bb33 0x652dd 0x10e46b0 0x228ffc0 0x228433c 0x228feaf 0x1042bd 0x4cb56 0x4b66f 0x4b589 0x4a7e4 0x4a61e 0x4b3d9 0x4e2d2 0xf899c 0x45574 0x4576f 0x45905 0x4e917 0x1296c 0x1394b 0x24cb5 0x25beb 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1317a 0x14ffc 0x1c5d 0x1b85)
libc++abi.dylib: terminate called throwing an exception
(lldb)
이 추적 출력에서, 나는 collectionView:numberOfItemsInSection
에 보낸 인수 중 하나 추측하고하는 것은 잘못된 유형입니다,하지만 난 그 문제를 해결하는 것입니다 아무 생각이 멀리 있기 때문에 필자가 작성한 코드가 아니라 프레임 워크 자체에 문제가 있다는 것을 알 수 있습니다.
전 완전히 잘못 됐나요? 누구든지 이것에 대해 어떤 생각을 밝힐 수 있습니까?
SIGABRT
오류에 관해 온라인으로 읽은 후, 시뮬레이터를 재설정하고 Xcode 및 MAc 자체를 여러 번 재시동했지만 아무 소용이 없습니다.
도움이 매우 감사 할 것입니다.
그런 경우 사전에서 가져 오는 위치에 null 변수가 있는지 확인할 수 있습니다. –
어느 사전? 이것이 내 코드에서 사전을 사용하지 않는다는 의미입니다. – Jimmery
왜 scrollview 내부에 collectionview를 추가합니까? –