UICollectionview self sizing cells is not working - ios

I want to use self sizing cells in my collection view.
My cells don't use auto layout -
I've implemented the methods as required but still they are not resizing properly.
Attached is the code:
#interface Cell : UICollectionViewCell
#end
#implementation Cell
-(CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake(320, 200);
}
// I have tried with and without this
-(UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
CGRect frame = attributes.frame;
frame.size = CGSizeMake(320, 200);
return attributes;
}
#end
#interface ViewController () <UICollectionViewDataSource>
#property (nonatomic,strong) UICollectionView *collectionView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
[self.view addSubview:self.collectionView];
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.collectionView registerClass:[Cell class] forCellWithReuseIdentifier:#"cell"];
self.collectionView.dataSource = self;
layout.estimatedItemSize = CGSizeMake(320, 10);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 10;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"cell" forIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor redColor];
return cell;
}
Also when rotating the device I get a crash:
*** Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UIFlowLayoutSupport.m:763
2015-03-08 11:09:06.430 TestSelfSizingCells[77344:3177236] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error'
*** First throw call stack:
(
0 CoreFoundation 0x000000010881bf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001084b4bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010881bd9a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001080d15df -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000109298e53 -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:] + 9052
5 UIKit 0x000000010925f96c __56-[UICollectionViewFlowLayout _updateItemsLayoutForRect:]_block_invoke + 509
6 CoreFoundation 0x0000000108754042 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
7 CoreFoundation 0x000000010875379c -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 300
8 UIKit 0x000000010925f69c -[UICollectionViewFlowLayout _updateItemsLayoutForRect:] + 780
9 UIKit 0x000000010925fce2 -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 583
10 UIKit 0x000000010925cde6 -[UICollectionViewFlowLayout _layoutAttributesForItemsInRect:] + 646
11 UIKit 0x000000010925e268 -[UICollectionViewFlowLayout layoutAttributesForElementsInRect:] + 119
12 UIKit 0x0000000109274130 __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 144
13 UIKit 0x0000000109273627 -[UICollectionViewData validateLayoutInRect:] + 1396
14 UIKit 0x000000010923b7b8 -[UICollectionView layoutSubviews] + 170
15 UIKit 0x0000000108c81973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
16 QuartzCore 0x000000010c4f6de8 -[CALayer layoutSublayers] + 150
17 QuartzCore 0x000000010c4eba0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
18 QuartzCore 0x000000010c4f6d1d -[CALayer layoutIfNeeded] + 162
19 UIKit 0x0000000108d4374a -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:newSize:] + 211
20 UIKit 0x0000000108d47e84 __95-[UIViewController(AdaptiveSizing) _window:viewWillTransitionToSize:withTransitionCoordinator:]_block_invoke2889 + 73
21 UIKit 0x0000000109361a0e -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] + 217
22 UIKit 0x000000010935ef2e -[_UIViewControllerTransitionContext __runAlongsideAnimations] + 139
23 UIKit 0x00000001090964d4 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 96
24 UIKit 0x0000000108c7a362 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 473
25 UIKit 0x0000000108c7a5b7 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 57
26 UIKit 0x0000000109096430 -[_UIWindowRotationAnimationController animateTransition:] + 408
27 UIKit 0x0000000108c52704 -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 761
28 UIKit 0x0000000108c54ac0 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 2134
29 UIKit 0x0000000108c55092 -[UIWindow _setRotatableClient:toOrientation:applyTransformToWindow:updateStatusBar:duration:force:isRotating:] + 559
30 UIKit 0x0000000108c541ee -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 116
31 UIKit 0x0000000108c54174 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
32 UIKit 0x0000000108c54021 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 122
33 UIKit 0x0000000108c53100 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 98
34 UIKit 0x0000000108c53079 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 386
35 UIKit 0x0000000108c53450 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 316
36 CoreFoundation 0x00000001087ebcec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
37 CoreFoundation 0x00000001086eb8a4 _CFXNotificationPost + 2484
38 Foundation 0x00000001080126b8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
39 UIKit 0x0000000108e70efc -[UIDevice setOrientation:animated:] + 282
40 UIKit 0x0000000108c1c476 -[UIApplication handleEvent:withNewEvent:] + 1474
41 UIKit 0x0000000108c1c90a -[UIApplication sendEvent:] + 79
42 UIKit 0x0000000108c086af _UIApplicationHandleEvent + 593
43 GraphicsServices 0x000000010bdec33e _PurpleEventCallback + 756
44 GraphicsServices 0x000000010bdebe26 PurpleEventCallback + 35
45 CoreFoundation 0x00000001087517c9 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
46 CoreFoundation 0x000000010875173b __CFRunLoopDoSource1 + 475
47 CoreFoundation 0x0000000108746f88 __CFRunLoopRun + 2200
48 CoreFoundation 0x0000000108746486 CFRunLoopRunSpecific + 470
49 GraphicsServices 0x000000010bdea9f0 GSEventRunModal + 161
50 UIKit 0x0000000108c08420 UIApplicationMain + 1282
51 TestSelfSizingCells 0x0000000107f87853 main + 115
52 libdyld.dylib 0x000000010adab145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I've also noticed that when using different screen sizes the results very. For instance in iPhone 5 the cells look "ok" in the beginning. But after a while they get screwed up.
Also in iPhone 6 simulator, the collection view doesn't scroll at all , until I rotate the device back and forth, and then eventually the app crashes.

Related

Why UITableView is not displaying on UIViewController?

I am trying to set up a UITableView inside of a UIViewController. I am using storyboard. but when running it on the simulator, the tableview does not display. Here is the simple view in Xcode:
#implementation ForthViewController{
NSArray *menuItems;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSArray *o = [prefs mutableArrayValueForKey:#"option"];
NSLog(#"%#",o);
menuItems =[NSArray arrayWithArray:o];
[self viewrequest];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [menuItems objectAtIndex:indexPath.row];
return cell;
}
I am getting following error:
2016-11-29 11:57:44.987 Wellness_24x7[1400:46606] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7a67d160
2016-11-29 11:57:45.010 Wellness_24x7[1400:46606] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x7a67d160'
*** First throw call stack:
(
0 CoreFoundation 0x00b4da14 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0060ee02 objc_exception_throw + 50
2 CoreFoundation 0x00b56d63 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x00a946bd ___forwarding___ + 1037
4 CoreFoundation 0x00a9428e _CF_forwarding_prep_0 + 14
5 UIKit 0x01884c1c -[UITableViewLabel setText:] + 120
6 Wellness_24x7 0x000f16c4 -[ForthViewController tableView:cellForRowAtIndexPath:] + 372
7 UIKit 0x014df398 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 822
8 UIKit 0x014df4e1 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
9 UIKit 0x014af948 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3347
10 UIKit 0x014ce0d6 __29-[UITableView layoutSubviews]_block_invoke + 52
11 UIKit 0x014e919e -[UITableView _performWithCachedTraitCollection:] + 88
12 UIKit 0x014cdfab -[UITableView layoutSubviews] + 214
13 UIKit 0x01424008 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
14 libobjc.A.dylib 0x00623059 -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x0569280a -[CALayer layoutSublayers] + 144
16 QuartzCore 0x056864ee _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
17 QuartzCore 0x05694d2a -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 44
18 UIKit 0x014117c0 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1258
19 UIKit 0x014112c2 -[UIView(Hierarchy) layoutIfNeeded] + 82
20 UIKit 0x01585420 -[UITabBarController _layoutViewController:] + 845
21 UIKit 0x0158557a -[UITabBarController _wrapperViewForViewController:] + 262
22 UIKit 0x01591ba6 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 787
23 UIKit 0x01590a0e -[UITabBarController transitionFromViewController:toViewController:] + 76
24 UIKit 0x0158c0dd -[UITabBarController _setSelectedViewController:] + 453
25 UIKit 0x0158bee4 -[UITabBarController setSelectedViewController:] + 252
26 UIKit 0x01590839 -[UITabBarController _tabBarItemClicked:] + 587
27 libobjc.A.dylib 0x006230b5 -[NSObject performSelector:withObject:withObject:] + 84
28 UIKit 0x01359b79 -[UIApplication sendAction:to:from:forEvent:] + 118
29 UIKit 0x01359af8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
30 UIKit 0x017a70fb -[UITabBar _sendAction:withEvent:] + 525
31 libobjc.A.dylib 0x006230b5 -[NSObject performSelector:withObject:withObject:] + 84
32 UIKit 0x01359b79 -[UIApplication sendAction:to:from:forEvent:] + 118
33 UIKit 0x01359af8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
34 UIKit 0x014f98f8 -[UIControl sendAction:to:forEvent:] + 79
35 UIKit 0x014f9c78 -[UIControl _sendActionsForEvents:withEvent:] + 408
36 UIKit 0x014f9938 -[UIControl sendActionsForControlEvents:] + 48
37 UIKit 0x017ace41 -[UITabBar(Static) _buttonUp:] + 123
38 libobjc.A.dylib 0x006230b5 -[NSObject performSelector:withObject:withObject:] + 84
39 UIKit 0x01359b79 -[UIApplication sendAction:to:from:forEvent:] + 118
40 UIKit 0x01359af8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
41 UIKit 0x014f98f8 -[UIControl sendAction:to:forEvent:] + 79
42 UIKit 0x014f9c78 -[UIControl _sendActionsForEvents:withEvent:] + 408
43 UIKit 0x014f8c7e -[UIControl touchesEnded:withEvent:] + 714
44 UIKit 0x013d6182 -[UIWindow _sendTouchesForEvent:] + 1095
45 UIKit 0x013d7220 -[UIWindow sendEvent:] + 1159
46 UIKit 0x0137bf93 -[UIApplication sendEvent:] + 266
47 UIKit 0x01351668 _UIApplicationHandleEventQueue + 7802
48 CoreFoundation 0x00a676ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
49 CoreFoundation 0x00a5d38b __CFRunLoopDoSources0 + 523
50 CoreFoundation 0x00a5c7a8 __CFRunLoopRun + 1032
51 CoreFoundation 0x00a5c0e6 CFRunLoopRunSpecific + 470
52 CoreFoundation 0x00a5befb CFRunLoopRunInMode + 123
53 GraphicsServices 0x05133664 GSEventRunModal + 192
54 GraphicsServices 0x051334a1 GSEventRun + 104
55 UIKit 0x01357bfa UIApplicationMain + 160
56 Wellness_24x7 0x000cba6a main + 138
57 libdyld.dylib 0x033c6a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Change this line
cell.textLabel.text = [menuItems objectAtIndex:indexPath.row];
with this
cell.textLabel.text = [NSString stringWithFormat:#"%#",[menuItems objectAtIndex:indexPath.row]];
Problem - The reason of the crash is cell.textLabel.text is expecting a NSString value and you are passing NSCFNumber in it so you need to convert NSCFNumber to NSString

Adding CollectionView programmatically

I'm attempting to add a CollectionView to my application with images. So I have setup one cell in the xib file and added an imageview, gave the cell identifier "Cell" for now and set it's delegate and datasource to the file's owner.
The issue I am having right now is that the application crashes whenever I enter the screen with that CollectionView.
2014-02-12 10:26:46.429 CollectionApp[509:a0b] *** Assertion failure in -[CollectionViewController loadView], /SourceCache/UIKit_Sim/UIKit-2903.23/UICollectionViewController.m:166
2014-02-12 10:26:46.510 CollectionApp[509:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] loaded the "34q-Sl-gDP-view-cX9-PP-w1h" nib but didn't get a UICollectionView.'
*** First throw call stack:
(
0 CoreFoundation 0x0191b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0169e8b6 objc_exception_throw + 44
2 CoreFoundation 0x0191b448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0127efee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x008eaec3 -[UICollectionViewController loadView] + 582
5 UIKit 0x003c90ae -[UIViewController loadViewIfRequired] + 78
6 UIKit 0x003c95b4 -[UIViewController view] + 35
7 UIKit 0x004003ae -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 407
8 UIKit 0x003ffbd2 -[UITabBarController transitionFromViewController:toViewController:] + 63
9 UIKit 0x003fbfbb -[UITabBarController _setSelectedViewController:] + 279
10 UIKit 0x003fbe9c -[UITabBarController setSelectedViewController:] + 180
11 UIKit 0x003fface -[UITabBarController _tabBarItemClicked:] + 312
12 libobjc.A.dylib 0x016b0874 -[NSObject performSelector:withObject:withObject:] + 77
13 UIKit 0x002b70c2 -[UIApplication sendAction:to:from:forEvent:] + 108
14 UIKit 0x002b704e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
15 UIKit 0x00565659 -[UITabBar _sendAction:withEvent:] + 479
16 libobjc.A.dylib 0x016b081f -[NSObject performSelector:withObject:] + 70
17 UIKit 0x002b70c2 -[UIApplication sendAction:to:from:forEvent:] + 108
18 UIKit 0x002b704e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
19 UIKit 0x003af0c1 -[UIControl sendAction:to:forEvent:] + 66
20 UIKit 0x003af484 -[UIControl _sendActionsForEvents:withEvent:] + 577
21 UIKit 0x003af0f6 -[UIControl sendActionsForControlEvents:] + 48
22 UIKit 0x00569f80 -[UITabBar(Static) _buttonUp:] + 123
23 libobjc.A.dylib 0x016b0874 -[NSObject performSelector:withObject:withObject:] + 77
24 UIKit 0x002b70c2 -[UIApplication sendAction:to:from:forEvent:] + 108
25 UIKit 0x002b704e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
26 UIKit 0x003af0c1 -[UIControl sendAction:to:forEvent:] + 66
27 UIKit 0x003af484 -[UIControl _sendActionsForEvents:withEvent:] + 577
28 UIKit 0x003ae733 -[UIControl touchesEnded:withEvent:] + 641
29 UIKit 0x002f451d -[UIWindow _sendTouchesForEvent:] + 852
30 UIKit 0x002f5184 -[UIWindow sendEvent:] + 1232
31 UIKit 0x002c8e86 -[UIApplication sendEvent:] + 242
32 UIKit 0x002b318f _UIApplicationHandleEventQueue + 11421
33 CoreFoundation 0x018a483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
34 CoreFoundation 0x018a41cb __CFRunLoopDoSources0 + 235
35 CoreFoundation 0x018c129e __CFRunLoopRun + 910
36 CoreFoundation 0x018c0ac3 CFRunLoopRunSpecific + 467
37 CoreFoundation 0x018c08db CFRunLoopRunInMode + 123
38 GraphicsServices 0x0359c9e2 GSEventRunModal + 192
39 GraphicsServices 0x0359c809 GSEventRun + 104
40 UIKit 0x002b5d3b UIApplicationMain + 1225
41 CollectionApp 0x0000ed9d main + 141
42 libdyld.dylib 0x01f57725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here's my CollectionViewController.h
#import "CollectionViewController.h"
#interface CollectionViewController () {
NSArray * listImages;
}
#end
#implementation CollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
listImages = [NSArray arrayWithObjects:#"7513-kirjatkuivumassa.jpg", #"kuppi.jpg", #"kuva1.jpg", #"juna-042.jpg", #"rautio-valamonruusut-helleaamuna-maalaus.jpg", #"pysähtynyt1.jpg", #"Screen-Shot-2013-02-20-at-21.07.38.jpg", #"sateenkaari.jpg", #"Screen-Shot-2013-02-21-at-17.04.22.jpg", #"moninaiset-e1391026376696.jpg", #"Tomperi+Metsä20111.jpg", #"3-shinot.jpg", #"Ulpukat.jpg", #"janne-e1391025808211.jpg", #"martikainen-240x240.jpg", #"takala-240x240.jpg", #"paanukallokaarme1.jpg", #"käsityök-240x240.jpg", #"kuvis-004.jpg", #"Se-on-hieno-2012-tammi-105x28x223.jpg", nil];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return listImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *listImageView = (UIImageView *)[cell viewWithTag:100];
listImageView.image = [UIImage imageNamed:[listImages objectAtIndex:indexPath.row]];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Please note that I am a complete noob when it comes to coding with Objective C. I'm currently attempting to study it.
All I had to do was to change
#interface CollectionViewController : UICollectionViewController
To
#interface CollectionViewController : UIViewController
Now there's no errors and everything works as intended.
You need register your xib cell to your UICollectionView on -(void)viewDidLoad of your view Controller.
[_tableView registerNib:[UINib nibWithNibName:#"nibName"
bundle:nil]
forCellReuseIdentifier:#"cellIdentifer"];

Unable to dequeue a cell with identifier [duplicate]

This question already has answers here:
Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:
(22 answers)
Closed 8 years ago.
here's the method causing the problem:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
// Configure the cell...
int row = [indexPath row];
Books *book = [myBooks objectAtIndex:row];
cell.bookName.text = book.bookName;
return cell;
}
full log:
2014-02-05 23:19:09.458 Books[1425:a0b] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:5251
2014-02-05 23:19:09.471 Books[1425:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TableCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x01739448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0109d23e -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x003135e3 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 170
5 Books 0x000032df -[TableViewController tableView:cellForRowAtIndexPath:] + 127
6 UIKit 0x0031dd2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
7 UIKit 0x0031de03 -[UITableView _createPreparedCellForGlobalRow:] + 69
8 UIKit 0x00302124 -[UITableView _updateVisibleCellsNow:] + 2378
9 UIKit 0x003155a5 -[UITableView layoutSubviews] + 213
10 UIKit 0x00299dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
11 libobjc.A.dylib 0x014ce81f -[NSObject performSelector:withObject:] + 70
12 QuartzCore 0x03af372a -[CALayer layoutSublayers] + 148
13 QuartzCore 0x03ae7514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
14 QuartzCore 0x03af3675 -[CALayer layoutIfNeeded] + 160
15 UIKit 0x00354ca3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
16 UIKit 0x00273d27 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
17 UIKit 0x002728c6 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
18 UIKit 0x00272798 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
19 UIKit 0x00272820 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
20 UIKit 0x002718ba __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
21 UIKit 0x0027181c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
22 UIKit 0x00272573 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
23 UIKit 0x00275b66 -[UIWindow setDelegate:] + 449
24 UIKit 0x00346dc7 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
25 UIKit 0x0026b7cc -[UIWindow addRootViewControllerViewIfPossible] + 609
26 UIKit 0x0026b947 -[UIWindow _setHidden:forced:] + 312
27 UIKit 0x0026bbdd -[UIWindow _orderFrontWithoutMakingKey] + 49
28 UIKit 0x0027644a -[UIWindow makeKeyAndVisible] + 65
29 UIKit 0x002298e0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
30 UIKit 0x0022dfb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
31 UIKit 0x0024242c -[UIApplication handleEvent:withNewEvent:] + 3447
32 UIKit 0x00242999 -[UIApplication sendEvent:] + 85
33 UIKit 0x0022fc35 _UIApplicationHandleEvent + 736
34 GraphicsServices 0x0368c2eb _PurpleEventCallback + 776
35 GraphicsServices 0x0368bdf6 PurpleEventCallback + 46
36 CoreFoundation 0x016b4dd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
37 CoreFoundation 0x016b4b0b __CFRunLoopDoSource1 + 523
38 CoreFoundation 0x016df7ec __CFRunLoopRun + 2156
39 CoreFoundation 0x016deb33 CFRunLoopRunSpecific + 467
40 CoreFoundation 0x016de94b CFRunLoopRunInMode + 123
41 UIKit 0x0022d6ed -[UIApplication _run] + 840
42 UIKit 0x0022f94b UIApplicationMain + 1225
43 Books 0x000038bd main + 141
44 libdyld.dylib 0x01d75725 start + 0
45 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You can directly set the identifier using the storyboard like this.
From the documentation:
Important: You must register a class or nib file using the
registerNib:forCellReuseIdentifier: or
registerClass:forCellReuseIdentifier: method before calling this
method.
You need to register the cell as a usable class for that identifier. Call this after you initialize your UITableView (probably in viewDidLoad)
[self.tableView registerClass:[TableCell class] forCellReuseIdentifier:CellIdentifier]
This assumes CellIdentifier has been moved somewhere where it can be accessed from here.
Try this:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[[TableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
int row = [indexPath row];
Books *book = [myBooks objectAtIndex:row];
cell.bookName.text = book.bookName;
return cell;
}

Keep getting breakpoint error when trying to run iOS application on iphone simulator with xcode 5

I just started creating a new checklist app for the first time.
So far I have added a Table View object and Table View Cell object to the app's UI in main.storyboard.
I then went to my View Controller header file and made sure to change the superclass type to "UITableViewController".
I then went to my View Controller main file and added the following methods:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell *)tableview:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"];
return cell;
}
I keep getting a breakpoint error and cannot get the app to run on the iPhone simulator. I have tried starting from scratch and recreating this app 3 times now and have also tried using different simulators, and still nothing is working.
Whenever I try running the app this is the final output in the debug console:
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Also, here is a link to a screenshot of what my xcode looks like when I try to run the program and get the breakpoint error: http://oi40.tinypic.com/25im3kn.jpg
I have gotten breakpoint errors many times in the past but usually can fix everything by just going to Debug > Deactivate Breakpoints but that is not working for me right now.
Any help is greatly appreciated thank you.
PS. Also, here is the entire output in the debug console log:
2013-12-18 18:25:55.183 Checklists[4910:70b] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit- 2903.23/UITableView.m:6246
2013-12-18 18:25:55.190 Checklists[4910:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(
0 CoreFoundation 0x017385e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bb8b6 objc_exception_throw + 44
2 CoreFoundation 0x01738448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0109bfee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x003123d5 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 426
5 UIKit 0x0028b3ef +[UIView(Animation) performWithoutAnimation:] + 82
6 UIKit 0x0028b438 +[UIView(Animation) _performWithoutAnimation:] + 40
7 UIKit 0x00312226 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
8 UIKit 0x0031863d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
9 UIKit 0x003186f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
10 UIKit 0x002fc774 -[UITableView _updateVisibleCellsNow:] + 2378
11 UIKit 0x0030fe95 -[UITableView layoutSubviews] + 213
12 UIKit 0x00294267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
13 libobjc.A.dylib 0x014cd81f -[NSObject performSelector:withObject:] + 70
14 QuartzCore 0x03b462ea -[CALayer layoutSublayers] + 148
15 QuartzCore 0x03b3a0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16 QuartzCore 0x03b46235 -[CALayer layoutIfNeeded] + 160
17 UIKit 0x0034f613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
18 UIKit 0x0026e177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
19 UIKit 0x0026cd16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
20 UIKit 0x0026cbe8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
21 UIKit 0x0026cc70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
22 UIKit 0x0026bd0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
23 UIKit 0x0026bc6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
24 UIKit 0x0026c9c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
25 UIKit 0x0026ffb6 -[UIWindow setDelegate:] + 449
26 UIKit 0x00341737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
27 UIKit 0x00265c1c -[UIWindow addRootViewControllerViewIfPossible] + 609
28 UIKit 0x00265d97 -[UIWindow _setHidden:forced:] + 312
29 UIKit 0x0026602d -[UIWindow _orderFrontWithoutMakingKey] + 49
30 UIKit 0x0027089a -[UIWindow makeKeyAndVisible] + 65
31 UIKit 0x00223cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
32 UIKit 0x002283a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
33 UIKit 0x0023c87c -[UIApplication handleEvent:withNewEvent:] + 3447
34 UIKit 0x0023cde9 -[UIApplication sendEvent:] + 85
35 UIKit 0x0022a025 _UIApplicationHandleEvent + 736
36 GraphicsServices 0x036df2f6 _PurpleEventCallback + 776
37 GraphicsServices 0x036dee01 PurpleEventCallback + 46
38 CoreFoundation 0x016b3d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
39 CoreFoundation 0x016b3a9b __CFRunLoopDoSource1 + 523
40 CoreFoundation 0x016de77c __CFRunLoopRun + 2156
41 CoreFoundation 0x016ddac3 CFRunLoopRunSpecific + 467
42 CoreFoundation 0x016dd8db CFRunLoopRunInMode + 123
43 UIKit 0x00227add -[UIApplication _run] + 840
44 UIKit 0x00229d3b UIApplicationMain + 1225
45 Checklists 0x00001b7d main + 141
46 libdyld.dylib 0x01d7670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
PPS. After making your change, my view controller main file now looks like this:
#import "ChecklistsViewController.h"
#interface ChecklistsViewController ()
#end
#implementation ChecklistsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(UITableViewCell *)tableview:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"]; if(!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"ChecklistItem"]; }
return cell;
}
#end
I still get an error and now this is what the console log is showing:
2013-12-18 18:42:14.609 Checklists[5014:70b] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit- 2903.23/UITableView.m:6246
2013-12-18 18:42:14.614 Checklists[5014:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x01739448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0109cfee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x003133d5 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 426
5 UIKit 0x0028c3ef +[UIView(Animation) performWithoutAnimation:] + 82
6 UIKit 0x0028c438 +[UIView(Animation) _performWithoutAnimation:] + 40
7 UIKit 0x00313226 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
8 UIKit 0x0031963d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
9 UIKit 0x003196f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
10 UIKit 0x002fd774 -[UITableView _updateVisibleCellsNow:] + 2378
11 UIKit 0x00310e95 -[UITableView layoutSubviews] + 213
12 UIKit 0x00295267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
13 libobjc.A.dylib 0x014ce81f -[NSObject performSelector:withObject:] + 70
14 QuartzCore 0x03b472ea -[CALayer layoutSublayers] + 148
15 QuartzCore 0x03b3b0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16 QuartzCore 0x03b47235 -[CALayer layoutIfNeeded] + 160
17 UIKit 0x00350613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
18 UIKit 0x0026f177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
19 UIKit 0x0026dd16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
20 UIKit 0x0026dbe8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
21 UIKit 0x0026dc70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
22 UIKit 0x0026cd0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
23 UIKit 0x0026cc6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
24 UIKit 0x0026d9c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
25 UIKit 0x00270fb6 -[UIWindow setDelegate:] + 449
26 UIKit 0x00342737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
27 UIKit 0x00266c1c -[UIWindow addRootViewControllerViewIfPossible] + 609
28 UIKit 0x00266d97 -[UIWindow _setHidden:forced:] + 312
29 UIKit 0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49
30 UIKit 0x0027189a -[UIWindow makeKeyAndVisible] + 65
31 UIKit 0x00224cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
32 UIKit 0x002293a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
33 UIKit 0x0023d87c -[UIApplication handleEvent:withNewEvent:] + 3447
34 UIKit 0x0023dde9 -[UIApplication sendEvent:] + 85
35 UIKit 0x0022b025 _UIApplicationHandleEvent + 736
36 GraphicsServices 0x036e02f6 _PurpleEventCallback + 776
37 GraphicsServices 0x036dfe01 PurpleEventCallback + 46
38 CoreFoundation 0x016b4d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
39 CoreFoundation 0x016b4a9b __CFRunLoopDoSource1 + 523
40 CoreFoundation 0x016df77c __CFRunLoopRun + 2156
41 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467
42 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123
43 UIKit 0x00228add -[UIApplication _run] + 840
44 UIKit 0x0022ad3b UIApplicationMain + 1225
45 Checklists 0x00002aed main + 141
46 libdyld.dylib 0x01d7770d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The problem is that the code dequeueReusableCellWithIdentifier is not returning a cell.
Check if your cell in the XIB as the Reuse Identifier set to "ChecklistItem"
If the dequeueReusableCellWithIdentifier returns nil create a new cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"];
if(!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"ChecklistItem"];
}
That should fix your problem.

CollectionViewCell unrecognized selector sent to instance

In my app I will use a collection view, but I'm having issue. I designed the collection view in the storyboard. I inserted a collection view in a view controller and I connected the delegate and the data source to the class (CategoryViewController.m) who has to manage this view controller.
I created a very simple cell in which I put an image view, then I create a class with subclass UICollectionViewCell, then I choose the class who manage the cell and I connect the image view to this class.
In the CategoryViewController.m I setup an array in which there are the image I want to show and I used the delegate methods of the UICollectionView, when I run the app it says me: unrecognized selector sent to instance. I will put here the code so you can help me to fix it:
Code to create the array of image:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIImage *image1 = [UIImage imageNamed:#"image_glasses.png"];
UIImage *image2 = [UIImage imageNamed:#"image_jacket.png"];
UIImage *image3 = [UIImage imageNamed:#"image_pants.png"];
UIImage *image4 = [UIImage imageNamed:#"image_scent.png"];
imageArray = [NSArray arrayWithObjects:image1, image2, image3, image4, nil];
}
Delegate methods of the UICollectionView:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return imageArray.count;
}
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
UIImage *image = [UIImage imageNamed:imageArray[indexPath.row]];
cell.imageViewCell.image = image;
return cell;
}
When I run the app it crashes here: UIImage *image = [UIImage imageNamed:imageArray[indexPath.row]];, what's wrong in my methods?
Update:
Here's the full crash log:
2013-11-27 10:54:34.853 BitmamaShop[1579:70b] -[UIImage stringByDeletingPathExtension]: unrecognized selector sent to instance 0xbe79910
2013-11-27 10:54:34.858 BitmamaShop[1579:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage stringByDeletingPathExtension]: unrecognized selector sent to instance 0xbe79910'
*** First throw call stack:
(
0 CoreFoundation 0x025445e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x022c78b6 objc_exception_throw + 44
2 CoreFoundation 0x025e1903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0253490b ___forwarding___ + 1019
4 CoreFoundation 0x025344ee _CF_forwarding_prep_0 + 14
5 UIKit 0x01687d65 -[_UIAssetManager imageNamed:scale:idiom:subtype:cachingOptions:] + 42
6 UIKit 0x016880c2 -[_UIAssetManager imageNamed:scale:idiom:subtype:] + 73
7 UIKit 0x0168810e -[_UIAssetManager imageNamed:idiom:subtype:] + 71
8 UIKit 0x0168814f -[_UIAssetManager imageNamed:idiom:] + 60
9 UIKit 0x01688189 -[_UIAssetManager imageNamed:] + 53
10 UIKit 0x01062173 +[UIImage imageNamed:] + 57
11 BitmamaShop 0x0000794f -[CategoryViewController collectionView:cellForItemAtIndexPath:] + 255
12 UIKit 0x01647bc8 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 257
13 UIKit 0x01649217 -[UICollectionView _updateVisibleCellsNow:] + 3677
14 UIKit 0x0164c57f -[UICollectionView layoutSubviews] + 267
15 UIKit 0x010a0267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
16 libobjc.A.dylib 0x022d981f -[NSObject performSelector:withObject:] + 70
17 QuartzCore 0x00d022ea -[CALayer layoutSublayers] + 148
18 QuartzCore 0x00cf60d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
19 QuartzCore 0x00d04715 -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 43
20 UIKit 0x01092c76 -[UIView(Hierarchy) layoutBelowIfNeeded] + 595
21 UIKit 0x01092a1d -[UIView(Hierarchy) layoutIfNeeded] + 74
22 UIKit 0x0116ef14 -[UINavigationController _layoutViewController:] + 1062
23 UIKit 0x0116e136 -[UINavigationController _layoutTopViewController] + 176
24 UIKit 0x0116c365 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 429
25 UIKit 0x0135b5f6 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 328
26 UIKit 0x0135b8fb -[UINavigationTransitionView _cleanupTransition] + 703
27 UIKit 0x0135b93a -[UINavigationTransitionView _navigationTransitionDidStop] + 55
28 UIKit 0x01081c6c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 267
29 UIKit 0x01080455 +[UIViewAnimationState popAnimationState] + 334
30 UIKit 0x01094cf6 +[UIView(Animation) commitAnimations] + 36
31 UIKit 0x0135b3f9 -[UINavigationTransitionView transition:fromView:toView:] + 2795
32 UIKit 0x0135a906 -[UINavigationTransitionView transition:toView:] + 55
33 UIKit 0x0116fd47 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3186
34 UIKit 0x0117009c -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
35 UIKit 0x01170cb9 -[UINavigationController __viewWillLayoutSubviews] + 57
36 UIKit 0x012aa181 -[UILayoutContainerView layoutSubviews] + 213
37 UIKit 0x010a0267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
38 libobjc.A.dylib 0x022d981f -[NSObject performSelector:withObject:] + 70
39 QuartzCore 0x00d022ea -[CALayer layoutSublayers] + 148
40 QuartzCore 0x00cf60d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
41 QuartzCore 0x00cf5f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
42 QuartzCore 0x00c5dae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
43 QuartzCore 0x00c5ee71 _ZN2CA11Transaction6commitEv + 393
44 QuartzCore 0x00d1b430 +[CATransaction flush] + 52
45 UIKit 0x01051dc9 _afterCACommitHandler + 131
46 CoreFoundation 0x0250c4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
47 CoreFoundation 0x0250c41f __CFRunLoopDoObservers + 399
48 CoreFoundation 0x024ea344 __CFRunLoopRun + 1076
49 CoreFoundation 0x024e9ac3 CFRunLoopRunSpecific + 467
50 CoreFoundation 0x024e98db CFRunLoopRunInMode + 123
51 GraphicsServices 0x02eef9e2 GSEventRunModal + 192
52 GraphicsServices 0x02eef809 GSEventRun + 104
53 UIKit 0x01035d3b UIApplicationMain + 1225
54 BitmamaShop 0x0005980d main + 141
55 libdyld.dylib 0x0484970d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Your imageArray array contains UIImage objects. So you can use it directly. Instead of using
UIImage *image = [UIImage imageNamed:imageArray[indexPath.row]];
use
UIImage *image = imageArray[indexPath.row];
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
UIImage *image = [UIImage imageNamed:imageArray[indexPath.row]];
cell.imageViewCell.image = [imageArray objectAtIndex:indexPath.row];
return cell;
}
You have to create UIImageView outlet in custom cell class & connect it after doing this you write this code :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
cell.imageViewCell.image = [NSString stringWithFormat:#"%#",[imageArray objectAtIndex:indexPath.row]];
return cell;
}

Resources