Unable to dequeue a cell with identifier [duplicate] - ios

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;
}

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

Localized App crashes with NSRangeException

I have an iOS app that has been working quite well in two languages – I know added some stuff, already keeping in mind using NSLocalizedString for localization etc. The english version of the app works fine so far, but the second language version crashes right after starting. Why?
One should note that I have not added all NSLocalizedStrings in my localizable.strings file. Furthermore, I have two separate Storyboards for both english an german. Any help would be greatly appreciated!
2014-12-18 18:14:36.083 Coverdale[48297:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x002461e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x020538e5 objc_exception_throw + 44
2 CoreFoundation 0x001fa8b2 -[__NSArrayI objectAtIndex:] + 210
3 UIKit 0x0126a35f -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 127
4 UIKit 0x00fe3f34 -[UITableViewController tableView:indentationLevelForRowAtIndexPath:] + 61
5 UIKit 0x00e012cf __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1786
6 UIKit 0x00d7581f +[UIView(Animation) performWithoutAnimation:] + 82
7 UIKit 0x00d75868 +[UIView(Animation) _performWithoutAnimation:] + 40
8 UIKit 0x00e00bd0 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
9 UIKit 0x00e0813d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
10 UIKit 0x00e081f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
11 UIKit 0x00de9ece -[UITableView _updateVisibleCellsNow:] + 2428
12 UIKit 0x00dfe6a5 -[UITableView layoutSubviews] + 213
13 UIKit 0x00d7e964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x0206582b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x007c845a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x007bc244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x007bc0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x007227fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x00723b85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x00724258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x0020e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x0020e2bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x001ec254 __CFRunLoopRun + 1076
24 CoreFoundation 0x001eb9d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x001eb7eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x0406b5ee GSEventRunModal + 192
27 GraphicsServices 0x0406b42b GSEventRun + 104
28 UIKit 0x00d0ff9b UIApplicationMain + 1225
29 Coverdale 0x0009b95d main + 141
30 libdyld.dylib 0x028b9701 start + 1
31 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
EDIT
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"Error";
if (indexPath.section == 0) {
if(indexPath.row == 0)
{ /*..*/}
}
return cell;
}
Turns out I needed to implement indentationLevelForRowAtIndexPath and just return 0.

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;
}

Getting SIGABRT error

Am getting a SIGABRT error in main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); // SIGABRT error
}
}
Am getting this in the console, but can't understand it:
2013-10-24 15:21:30.278 Blog_Reader[45888:a0b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0xb779360
2013-10-24 15:21:30.293 Blog_Reader[45888:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to instance 0xb779360'
*** First throw call stack:
(
0 CoreFoundation 0x017345e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014b78b6 objc_exception_throw + 44
2 CoreFoundation 0x017d1903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172490b ___forwarding___ + 1019
4 CoreFoundation 0x017244ee _CF_forwarding_prep_0 + 14
5 Foundation 0x010fcb2d -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 39
6 Foundation 0x010fd79a -[NSConcreteMutableAttributedString initWithString:attributes:] + 293
7 UIKit 0x003d7116 -[UILabel _setText:] + 97
8 UIKit 0x003d72d4 -[UILabel setText:] + 40
9 Blog_Reader 0x00002c3d -[TableViewController tableView:cellForRowAtIndexPath:] + 301
10 UIKit 0x00318d2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
11 UIKit 0x00318e03 -[UITableView _createPreparedCellForGlobalRow:] + 69
12 UIKit 0x002fd124 -[UITableView _updateVisibleCellsNow:] + 2378
13 UIKit 0x003105a5 -[UITableView layoutSubviews] + 213
14 UIKit 0x00294dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
15 libobjc.A.dylib 0x014c981f -[NSObject performSelector:withObject:] + 70
16 QuartzCore 0x03aee72a -[CALayer layoutSublayers] + 148
17 QuartzCore 0x03ae2514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
18 QuartzCore 0x03aee675 -[CALayer layoutIfNeeded] + 160
19 UIKit 0x0034fca3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
20 UIKit 0x0026ed27 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
21 UIKit 0x0026d8c6 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
22 UIKit 0x0026d798 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
23 UIKit 0x0026d820 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
24 UIKit 0x0026c8ba __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
25 UIKit 0x0026c81c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
26 UIKit 0x0026d573 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
27 UIKit 0x00270b66 -[UIWindow setDelegate:] + 449
28 UIKit 0x00341dc7 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
29 UIKit 0x002667cc -[UIWindow addRootViewControllerViewIfPossible] + 609
30 UIKit 0x00266947 -[UIWindow _setHidden:forced:] + 312
31 UIKit 0x00266bdd -[UIWindow _orderFrontWithoutMakingKey] + 49
32 UIKit 0x0027144a -[UIWindow makeKeyAndVisible] + 65
33 Blog_Reader 0x000023bb -[AppDelegate application:didFinishLaunchingWithOptions:] + 267
34 UIKit 0x00223f65 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
35 UIKit 0x002247a5 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
36 UIKit 0x00228fb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
37 UIKit 0x0023d42c -[UIApplication handleEvent:withNewEvent:] + 3447
38 UIKit 0x0023d999 -[UIApplication sendEvent:] + 85
39 UIKit 0x0022ac35 _UIApplicationHandleEvent + 736
40 GraphicsServices 0x036872eb _PurpleEventCallback + 776
41 GraphicsServices 0x03686df6 PurpleEventCallback + 46
42 CoreFoundation 0x016afdd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
43 CoreFoundation 0x016afb0b __CFRunLoopDoSource1 + 523
44 CoreFoundation 0x016da7ec __CFRunLoopRun + 2156
45 CoreFoundation 0x016d9b33 CFRunLoopRunSpecific + 467
46 CoreFoundation 0x016d994b CFRunLoopRunInMode + 123
47 UIKit 0x002286ed -[UIApplication _run] + 840
48 UIKit 0x0022a94b UIApplicationMain + 1225
49 Blog_Reader 0x00002e2d main + 141
50 libdyld.dylib 0x01d70725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the TableViewController.m file:
#implementation TableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *blogPost1 = [NSDictionary dictionaryWithObjectsAndKeys:#"The Missing Widget in Android", #"title", #"Ben Jakuben", #"author", nil];
NSDictionary *blogPost2 = [NSDictionary dictionaryWithObjectsAndKeys:#"Getting Started with iOS Development", #"title", #"Amit Bijlani", #"author", nil];
NSDictionary *blogPost3 = [NSDictionary dictionaryWithObjectsAndKeys:#"An Interview with Shay Howe", #"title", #"Joe Villanueva", #"author", nil];
self.blogPosts = [NSArray arrayWithObjects:blogPost1, blogPost2, blogPost3, nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = [self.blogPosts objectAtIndex:indexPath.row];
return cell;
}
#end
You are storing NSDictionary instances in self.blogPosts, but then in
cell.textLabel.text = [self.blogPosts objectAtIndex:indexPath.row];
you are assigning one of them to text, which expects a NSString. The compiler is not catching it since objectAtIndex: returns an object of type id, which can potentially be anything.
A possible fix (but it really depends on what you need) could be
cell.textLabel.text = self.blogPosts[indexPath.row][#"title"];

Resources