Adding CollectionView programmatically - ios

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"];

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

UICollectionview self sizing cells is not working

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.

Crash attempting to set delegate of textfield

I have a lot of textfields and what I am trying to make them do is dismiss when the return key is used. In order for this to work you need to set the delegate of each textfield to self, like this [textfield setDelegate: self];. I have over 50 textfields in my project and in order to make it so they all dismiss I have to copy that line of code for each textfield. In the example below I used a for loop to try to shrink this down, but my project crashes and gives me this error when I try. Can someone tell me what im doing wrong and how i can fix this?
//.h
#interface InsertScheduleCGPS : UIViewController <UITextFieldDelegate>{
NSArray *Dayh;
IBOutlet UITextField *Day11;
}
#property(nonatomic, assign) id<UITextFieldDelegate> delegate;
#property (nonatomic,strong) NSArray *Dayh;
.
//.m
- (void)viewDidLoad
{
[super viewDidLoad];
Dayh = [NSArray arrayWithObjects:#"Day11", nil];
NSLog(#"euf");
for(int i=0; i<[self.Dayh count]; i++) {
NSLog(#"dd%#",[self.Dayh objectAtIndex:i]);
[[self.Dayh objectAtIndex:i] setDelegate: self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)Day11 {
[[self view] endEditing:YES];
return NO;
}
ERROR:
2014-01-18 19:15:26.712 Swepple[64912:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString setDelegate:]: unrecognized selector sent to instance 0x144ec'
*** First throw call stack:
(
0 CoreFoundation 0x0183b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x015be8b6 objc_exception_throw + 44
2 CoreFoundation 0x018d8903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0182b90b ___forwarding___ + 1019
4 CoreFoundation 0x0182b4ee _CF_forwarding_prep_0 + 14
5 Swepple 0x0000bbd6 -[InsertScheduleCGPS viewDidLoad] + 4262
6 UIKit 0x00440318 -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x004405b4 -[UIViewController view] + 35
8 UIKit 0x0044f361 -[UIViewController viewControllerForRotation] + 63
9 UIKit 0x00446f00 -[UIViewController _visibleView] + 84
10 UIKit 0x006d511a -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 5199
11 UIKit 0x0044c0fc -[UIViewController presentViewController:withTransition:completion:] + 6433
12 UIKit 0x0044c61f -[UIViewController presentViewController:animated:completion:] + 130
13 UIKit 0x0044c65f -[UIViewController presentModalViewController:animated:] + 56
14 UIKit 0x00870e16 -[UIStoryboardModalSegue perform] + 271
15 UIKit 0x0086107e -[UIStoryboardSegueTemplate _perform:] + 174
16 UIKit 0x00442280 -[UIViewController performSegueWithIdentifier:sender:] + 72
17 Swepple 0x000052d4 -[SecondViewController insert:] + 244
18 libobjc.A.dylib 0x015d0874 -[NSObject performSelector:withObject:withObject:] + 77
19 UIKit 0x0032e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
20 UIKit 0x0032e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
21 UIKit 0x004260c1 -[UIControl sendAction:to:forEvent:] + 66
22 UIKit 0x00426484 -[UIControl _sendActionsForEvents:withEvent:] + 577
23 UIKit 0x00425733 -[UIControl touchesEnded:withEvent:] + 641
24 UIKit 0x0036b51d -[UIWindow _sendTouchesForEvent:] + 852
25 UIKit 0x0036c184 -[UIWindow sendEvent:] + 1232
26 UIKit 0x0033fe86 -[UIApplication sendEvent:] + 242
27 UIKit 0x0032a18f _UIApplicationHandleEventQueue + 11421
28 CoreFoundation 0x017c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x017c41cb __CFRunLoopDoSources0 + 235
30 CoreFoundation 0x017e129e __CFRunLoopRun + 910
31 CoreFoundation 0x017e0ac3 CFRunLoopRunSpecific + 467
32 CoreFoundation 0x017e08db CFRunLoopRunInMode + 123
33 GraphicsServices 0x037e09e2 GSEventRunModal + 192
34 GraphicsServices 0x037e0809 GSEventRun + 104
35 UIKit 0x0032cd3b UIApplicationMain + 1225
36 Swepple 0x0000e04d main + 141
37 libdyld.dylib 0x01d7c70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You probably meant
Dayh = [NSArray arrayWithObjects:Day11, nil];
At present, Dayh is an array containing the string "Day11", not the text field.

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.

[<UIView 0x89bfd40> setValue:forUndefinedKey:]

Another problem that is causing my build to succeed, then terminate. As follows:
Error:
2013-09-30 20:21:23.708 The Solver[2566:a0b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x89bfd40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key welcomeBeta.'
*** First throw call stack:
(
0 CoreFoundation 0x023615e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bf8b6 objc_exception_throw + 44
2 CoreFoundation 0x023f16a1 -[NSException raise] + 17
3 Foundation 0x00f73c2e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00edff3b _NSSetUsingKeyValueSetter + 88
5 Foundation 0x00edf493 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 UIKit 0x0008f97b -[UIView(CALayerDelegate) setValue:forKey:] + 168
7 Foundation 0x00f4194a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
8 UIKit 0x002c6cd5 -[UIRuntimeOutletConnection connect] + 106
9 libobjc.A.dylib 0x014d17d2 -[NSObject performSelector:] + 62
10 CoreFoundation 0x0235cb6a -[NSArray makeObjectsPerformSelector:] + 314
11 UIKit 0x002c582e -[UINib instantiateWithOwner:options:] + 1417
12 UIKit 0x00137c95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
13 UIKit 0x0013843d -[UIViewController loadView] + 302
14 UIKit 0x0013873e -[UIViewController loadViewIfRequired] + 78
15 UIKit 0x00138c44 -[UIViewController view] + 35
16 UIKit 0x000615ad -[UIWindow addRootViewControllerViewIfPossible] + 66
17 UIKit 0x00061947 -[UIWindow _setHidden:forced:] + 312
18 UIKit 0x00061bdd -[UIWindow _orderFrontWithoutMakingKey] + 49
19 UIKit 0x0006c44a -[UIWindow makeKeyAndVisible] + 65
20 UIKit 0x0001f8e0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
21 UIKit 0x00023fb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
22 UIKit 0x0003842c -[UIApplication handleEvent:withNewEvent:] + 3447
23 UIKit 0x00038999 -[UIApplication sendEvent:] + 85
24 UIKit 0x00025c35 _UIApplicationHandleEvent + 736
25 GraphicsServices 0x022bf2eb _PurpleEventCallback + 776
26 GraphicsServices 0x022bedf6 PurpleEventCallback + 46
27 CoreFoundation 0x022dcdd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
28 CoreFoundation 0x022dcb0b __CFRunLoopDoSource1 + 523
29 CoreFoundation 0x023077ec __CFRunLoopRun + 2156
30 CoreFoundation 0x02306b33 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x0230694b CFRunLoopRunInMode + 123
32 UIKit 0x000236ed -[UIApplication _run] + 840
33 UIKit 0x0002594b UIApplicationMain + 1225
34 The Solver 0x000033dd main + 141
35 libdyld.dylib 0x059a5725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Code for UIControllerView with welcomeBeta (Button)
WelcomeUI.h:
#import <UIKit/UIKit.h>
#interface WelcomeUI : UIViewController
#property (weak, nonatomic) IBOutlet UIButton *welcomeStart;
#property (weak, nonatomic) IBOutlet UIButton *welcomeBeta;
#end
WelcomeUI.m:
#import "WelcomeUI.h"
#interface WelcomeUI ()
#end
#implementation WelcomeUI
- (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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Please let me know where I'm going wrong. Also explain in detail as I'm new to objective-c and Xcode.

Resources