I have a UITableViewCell that has 2 UIButton instances. Both buttons have a default image. Only the "bad" button has an image for the disabled state. Nothing more.
In the cell class these two buttons are declared as properties with the IBOutlet keyword:
#property (nonatomic, readonly) IBOutlet UIButton* buttonCall;
#property (nonatomic, readonly) IBOutlet UIButton* buttonGPS;
The connections between the 2 buttons in the .xib and the properties in the class are made.
So, when the .xib is loaded the following is done:
MyCell* cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell)
{
NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:#"MyCell" owner:nil options:nil];
cell = [nibContents objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// gps button
[cell.buttonGPS setTitle:[NSString stringWithFormat:#"%d", indexPath.row] forState:UIControlStateNormal];
[cell.buttonGPS addTarget:self action:#selector(actionGPS:) forControlEvents:UIControlEventTouchUpInside];
if (...condition...)
{
cell.buttonCall.enabled = NO;
[cell.buttonCall removeTarget:self action:#selector(actionCall:) forControlEvents:UIControlEventTouchUpInside];
}
else
{
cell.buttonCall.enabled = YES;
[cell.buttonCall setTitle:[...TheTitleString...] forState:UIControlStateNormal];
[cell.buttonCall addTarget:self action:#selector(actionCall:) forControlEvents:UIControlEventTouchUpInside];
}
When the view controller appears it goes successfully through (UITableViewCell*)tableView:cellForRowAtIndexPath: the necessary number of times. Then the app crashes with the following stack:
0 kill
...
[UIButton imageRectForContentRect:]
[UIButton(UIButtonInternal) _setupImageView]
[UIButton layoutSubviews]
...
start
I removed the image of the button and started crashing with stack:
0 kill
...
[UIButton layoutSubviews]
...
start
I added some identifier labels for the buttons - still crashing.
Removed the XCode-InterfaceBuilder connection for the "bad" button and the crashes stopped. But the button is not functional.
Any idea what is causing the crashes?
Call stack is:
0 CoreFoundation 0x013d406e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x019f0d0a objc_exception_throw + 44
2 CoreFoundation 0x013d5ced -[NSObject doesNotRecognizeSelector:] + 253
3 CoreFoundation 0x0133af00 ___forwarding___ + 432
4 CoreFoundation 0x0133ace2 _CF_forwarding_prep_0 + 50
5 UIKit 0x0086de3a -[UIButton imageRectForContentRect:] + 350
6 UIKit 0x0086ed5b -[UIButton(UIButtonInternal) _setupImageView] + 158
7 UIKit 0x0086e5f8 -[UIButton layoutSubviews] + 693
8 UIKit 0x0069f322 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 178
9 CoreFoundation 0x013d5e72 -[NSObject performSelector:withObject:] + 66
10 QuartzCore 0x0042092d -[CALayer layoutSublayers] + 266
11 QuartzCore 0x0042a827 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 231
12 QuartzCore 0x003b0fa7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 377
13 QuartzCore 0x003b2ea6 _ZN2CA11Transaction6commitEv + 374
14 QuartzCore 0x003b2580 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 80
15 CoreFoundation 0x013a89ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
16 CoreFoundation 0x0133f670 __CFRunLoopDoObservers + 384
17 CoreFoundation 0x0130b4f6 __CFRunLoopRun + 1174
18 CoreFoundation 0x0130adb4 CFRunLoopRunSpecific + 212
19 CoreFoundation 0x0130accb CFRunLoopRunInMode + 123
20 GraphicsServices 0x03258879 GSEventRunModal + 207
21 GraphicsServices 0x0325893e GSEventRun + 114
22 UIKit 0x00660a9b UIApplicationMain + 1175
23 MyApp 0x000023f9 main + 169
24 MyApp 0x00002345 start + 53
Exception is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x146acd8'
info symbol 0x146acd8
__kCFNull in section LC_SEGMENT.__DATA.__data of /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
The second scenario is similar. The exception, however, is exactly the same. Here is the call stack:
0 CoreFoundation 0x013d406e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x019f0d0a objc_exception_throw + 44
2 CoreFoundation 0x013d5ced -[NSObject doesNotRecognizeSelector:] + 253
3 CoreFoundation 0x0133af00 ___forwarding___ + 432
4 CoreFoundation 0x0133ace2 _CF_forwarding_prep_0 + 50
5 UIKit 0x0086e851 -[UIButton layoutSubviews] + 1294
6 UIKit 0x0069f322 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 178
7 CoreFoundation 0x013d5e72 -[NSObject performSelector:withObject:] + 66
8 QuartzCore 0x0042092d -[CALayer layoutSublayers] + 266
9 QuartzCore 0x0042a827 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 231
10 QuartzCore 0x003b0fa7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 377
11 QuartzCore 0x003b2ea6 _ZN2CA11Transaction6commitEv + 374
12 QuartzCore 0x003b2580 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 80
13 CoreFoundation 0x013a89ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
14 CoreFoundation 0x0133f670 __CFRunLoopDoObservers + 384
15 CoreFoundation 0x0130b4f6 __CFRunLoopRun + 1174
16 CoreFoundation 0x0130adb4 CFRunLoopRunSpecific + 212
17 CoreFoundation 0x0130accb CFRunLoopRunInMode + 123
18 GraphicsServices 0x03258879 GSEventRunModal + 207
19 GraphicsServices 0x0325893e GSEventRun + 114
20 UIKit 0x00660a9b UIApplicationMain + 1175
21 MyApp 0x000023f9 main + 169
22 MyApp 0x00002345 start + 53
From the exception, it looks like you think you are passing an NSString to the title of a button, and you are in fact passing an instance of NSNull. This is quite common if you are deriving your table view data from a JSON source or similar - NSNull is used if the source field does not exist.
The exception you get is that length is not a recognised selector for NSNull, which is true, and it seems to come up when the button is laying out its subviews, which it would do when you assign a new title. So I would focus your investigation in that area. Check to see what you are actually sending for the title of the button.
MyCell* cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell)
{
NSArray* nibContents = [[NSBundle mainBundle] loadNibNamed:#"MyCell" owner:nil options:nil];
cell = [nibContents objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell.buttonGPS addTarget:self action:#selector(actionGPS:) forControlEvents:UIControlEventTouchUpInside];
[cell.buttonCall addTarget:self action:#selector(actionCall:) forControlEvents:UIControlEventTouchUpInside];
}
// gps button
[cell.buttonGPS setTitle:[NSString stringWithFormat:#"%d", indexPath.row] forState:UIControlStateNormal];
if (...condition...)
{
cell.buttonCall.enabled = NO;
}
else
{
cell.buttonCall.enabled = YES;
[cell.buttonCall setTitle:[...TheTitleString...] forState:UIControlStateNormal];
}
Make these changes in ur code & check. I think some condition may be wrong, so b4 adding the target it was removed and when attempted it was crashing.
Related
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.
I have the following code and receive the error code indicated in title:
This is the only messages i send to User object (other than initialising it by using "new")
When I out comment addObject: it doesn't complain.
Can anybody help? Thanks!
self.freshUser.name = self.name.text;
self.freshUser.age = (int)self.age.text;
self.freshUser.gender = self.gender.text;
//NSLog(#"%#",[NSThread callStackSymbols]);
[appDelegate.users addObject:self.freshUser];
(My user object subclasses NSObject. it has more property that I don't use. just a little extra info)
-(UITableViewCell *)tableView:(UITableView *)tableViewPara cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UserCell *cell = [tableViewPara dequeueReusableCellWithIdentifier:usersTableIdentifier forIndexPath:indexPath];
if(indexPath.row == [appDelegate.users count]){
cell.nameLabel.text = #"+";
cell.nameLabel.font = [UIFont systemFontOfSize:36];
cell.bgImg.image = [UIImage imageNamed:#"background_gray"];
cell.statusImg.image = nil;
}else{
cell.nameLabel.text = appDelegate.users[indexPath.row];
cell.nameLabel.font = [UIFont systemFontOfSize:17];
cell.bgImg.image = [UIImage imageNamed:#"background_dark_red"];
cell.statusImg.image = [UIImage imageNamed:#"icon_cloud"];
}
cell.nameLabel.textAlignment = NSTextAlignmentCenter;
cell.nameLabel.textColor = [UIColor whiteColor];
cell.nameLabel.backgroundColor = [UIColor clearColor];
return cell;
}
space
0 CoreFoundation 0x000000010ff1bf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fbb4bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ff2304d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010fe7b27c ___forwarding___ + 988
4 CoreFoundation 0x000000010fe7ae18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001104d034b -[UILabel _setFont:] + 101
6 Raymio 0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991
7 UIKit 0x00000001103ff4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
8 UIKit 0x00000001103defb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
9 UIKit 0x00000001103f4e3c -[UITableView layoutSubviews] + 213
10 UIKit 0x0000000110381973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
11 QuartzCore 0x0000000113c09de8 -[CALayer layoutSublayers] + 150
12 QuartzCore 0x0000000113bfea0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000113bfe87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000113b6c63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000113b6d74a _ZN2CA11Transaction6commitEv + 390
16 QuartzCore 0x0000000113b6ddb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17 CoreFoundation 0x000000010fe50dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x000000010fe50d20 __CFRunLoopDoObservers + 368
19 CoreFoundation 0x000000010fe46b53 __CFRunLoopRun + 1123
20 CoreFoundation 0x000000010fe46486 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x00000001134fd9f0 GSEventRunModal + 161
22 UIKit 0x0000000110308420 UIApplicationMain + 1282
23 Raymio 0x000000010f678a83 main + 115
24 libdyld.dylib 0x00000001124ab145 start + 1
This line:
cell.nameLabel.text = appDelegate.users[indexPath.row];
You're trying to set a User object to the text of a label field. That's not going to work. You'll want this or something close:
cell.nameLabel.text = ((User *)appDelegate.users[indexPath.row]).name;
You shared your stack trace with us. A useful technique is to look in it for anything that references code you wrote. You may notice that line 6 references your StartViewController:
6 Raymio 0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991
You can show the relevant line of code by typing source list command using that address in the third column:
(lldb) source list -a 0x000000010f67857f
43 cell.nameLabel.text = #"+";
44 cell.nameLabel.font = [UIFont systemFontOfSize:36];
45 cell.bgImg.image = [UIImage imageNamed:#"background_gray"];
46 cell.statusImg.image = nil;
47 }else{
-> 48 cell.nameLabel.text = appDelegate.users[indexPath.row];
49 cell.nameLabel.font = [UIFont systemFontOfSize:17];
50 cell.bgImg.image = [UIImage imageNamed:#"background_dark_red"];
51 cell.statusImg.image = [UIImage imageNamed:#"icon_cloud"];
52 }
Clearly your line numbers and memory addresses will vary, but hopefully this will illustrate the idea. Scan the stack trace for anything that references your code, and examine that line of code for any potential issues.
By the way, this discussion. also shows you how to use the -[StartViewController tableView:cellForRowAtIndexPath:] + 991 of the stack trace to show the relevant line of code.
When i press my button, i got a error of access.
the error : Thread 1 : EXC_BAD_ACCESS(code=1,address=0xd0a937db)
TTest.h
#interface TTtest : NSObject
{
UIButton *monBouton ;
UIImage *skin;
}
- (void)initTest :(UIView*)vueDonne;
-(void)test:(id)sender;
TTest.m
- (void)initTest :(UIView*)vueDonne
{
skin = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:#"boutonG" ofType:#"png"]];
monBouton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
monBouton.frame = CGRectMake(50, 50, 45, 50);
[monBouton setImage:skin forState:UIControlStateNormal];
[monBouton addTarget:self action:#selector(test:) forControlEvents:UIControlEventTouchDown];
[vueDonne addSubview: monBouton];
}
-(void)test:(id)sender //didn't work because i have the probleme
{
NSLog(#"test clicked");
}
testViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
TTtest *test =[[TTtest alloc] init];
[test initTest:_testView]; //View of my application
}
EDIT:
If i add monBouton = [[UIButton alloc] init];
I get a problem of SIGABRT
2014-10-26 16:47:22.827 testAsk[2134:a0b] -[CALayerArray test:]: unrecognized selector sent to instance 0xa141ea0
2014-10-26 16:47:22.831 testAsk[2134:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray test:]: unrecognized selector sent to instance 0xa141ea0'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d6903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172990b ___forwarding___ + 1019
4 CoreFoundation 0x017294ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x014ce874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x0022c0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x0022c04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x003240c1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00324484 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x003231fd -[UIControl touchesBegan:withEvent:] + 254
11 UIKit 0x0026934b -[UIWindow _sendTouchesForEvent:] + 386
12 UIKit 0x0026a184 -[UIWindow sendEvent:] + 1232
13 UIKit 0x0023de86 -[UIApplication sendEvent:] + 242
14 UIKit 0x0022818f _UIApplicationHandleEventQueue + 11421
15 CoreFoundation 0x016c283f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
16 CoreFoundation 0x016c21cb __CFRunLoopDoSources0 + 235
17 CoreFoundation 0x016df29e __CFRunLoopRun + 910
18 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467
19 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123
20 GraphicsServices 0x0368e9e2 GSEventRunModal + 192
21 GraphicsServices 0x0368e809 GSEventRun + 104
22 UIKit 0x0022ad3b UIApplicationMain + 1225
23 testAsk 0x000027bd main + 141
24 libdyld.dylib 0x01d75725 start + 0
25 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The reason for the crash is that test object is dealloced when it receives the button action.
TTtest *test =[[TTtest alloc] init]; //dealloced after viewDidLoad
so try to make the test a property and use self.test.
self.test =[[TTtest alloc] init];
Doesn't look like you defined the selector "test"
-(void)test: (id) sender
NSLog(#"test clicked");
}
I've been trying to solve this problem for the past two days but I just can't find why it occurs, so I took it here to ask if you guys have any idea about it.
So I have a UITableView which I display some items in. I also have a UITableViewCell which I use as the cells.
I register the nib with my table view in the viewDidLoad:
[self.QuickPickDetailsTV registerNib:[UINib nibWithNibName:#"QuickPickItemCell"
bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:#"QuickPickItemCellReuseID"];
Then in the tableView:cellForRowAtIndexPath:, I reuse, populate, and return the cell as below:
static NSString *CellIdentifier = #"QuickPickItemCellReuseID";
QuickPickItemCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[QuickPickItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSDictionary *quickPickItem = [self.myQuickPickItems objectAtIndex:indexPath.row];
NSString *theQuickPickItemName = [quickPickItem valueForKey:#"name"];
[cell.mName setFont:[UIFont fontWithName:#"OpenSans" size:16]];
[cell.mName setText:NSLocalizedString(theQuickPickItemName, nil)];
return cell;
The method above gets called for the number of items it should display (as expected), and crashes with an strange error after the last cell is returned:
2014-08-02 13:03:38.008 TestApp[49701:607] -[__NSArrayI length]: unrecognized selector sent to instance 0x2e92fde0
2014-08-02 13:03:38.010 TestApp[49701:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x2e92fde0'
*** First throw call stack:
(
0 CoreFoundation 0x044f21e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x033888e5 objc_exception_throw + 44
2 CoreFoundation 0x0458f243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x044e250b ___forwarding___ + 1019
4 CoreFoundation 0x044e20ee _CF_forwarding_prep_0 + 14
5 UIKit 0x01ff8463 -[UILabel _shadow] + 45
6 UIKit 0x01ff98c2 -[UILabel drawTextInRect:] + 70
7 UIKit 0x01ffbdfc -[UILabel drawRect:] + 98
8 UIKit 0x01eaa453 -[UIView(CALayerDelegate) drawLayer:inContext:] + 504
9 QuartzCore 0x00dbaf39 -[CALayer drawInContext:] + 123
10 QuartzCore 0x00dbae6a _ZL16backing_callbackP9CGContextPv + 96
11 QuartzCore 0x00ca94fc CABackingStoreUpdate_ + 2656
12 QuartzCore 0x00dbae02 ___ZN2CA5Layer8display_Ev_block_invoke + 93
13 QuartzCore 0x00def2d7 x_blame_allocations + 15
14 QuartzCore 0x00dbac6d _ZN2CA5Layer8display_Ev + 1519
15 QuartzCore 0x00dbaeb9 -[CALayer _display] + 33
16 QuartzCore 0x00dba676 _ZN2CA5Layer7displayEv + 144
17 QuartzCore 0x00dbae93 -[CALayer display] + 33
18 QuartzCore 0x00daf043 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 323
19 QuartzCore 0x00daf0bc _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38
20 QuartzCore 0x00d157fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
21 QuartzCore 0x00d16b85 _ZN2CA11Transaction6commitEv + 393
22 QuartzCore 0x00d17258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
23 CoreFoundation 0x044ba36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
24 CoreFoundation 0x044ba2bf __CFRunLoopDoObservers + 399
25 CoreFoundation 0x04498254 __CFRunLoopRun + 1076
26 CoreFoundation 0x044979d3 CFRunLoopRunSpecific + 467
27 CoreFoundation 0x044977eb CFRunLoopRunInMode + 123
28 GraphicsServices 0x047e95ee GSEventRunModal + 192
29 GraphicsServices 0x047e942b GSEventRun + 104
30 UIKit 0x01e3bf9b UIApplicationMain + 1225
31 TestApp 0x00002c92 main + 130
32 TestApp 0x00002c05 start + 53
33 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I have searched all my code but I don't send length to any object in my code. I don't know where is the crash coming from since it is shown to be on my main.m.
I have tried turning on NSZombies as well, but I didn't get any warnings about released objects.
Any help will be appreciated!
Thanks
I am getting a memory error when I press my UIbuttons. I am creating these buttons dynamically in a custom class file, so everytime the class is called a certain number of buttons are created depending on the view controller. The code for their creation is as follows:
- (void)addTopicButtonsWithCount:(int)count andView:(UIScrollView*)referenceView
{
int i = 0;
for(NSString *theory in _chapterTheory)
{
[self makeButtonWithTitle:[NSString stringWithFormat:#"%#", self.chapterTheory[i][#"title"]] atPositionIndex:i andView:referenceView];
i++;
}
}
- (void)makeButtonWithTitle:(NSString *)title atPositionIndex:(NSInteger)index andView: (UIScrollView*)referenceView
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(80, 80+(60*index), 160, 40);
button.tag = index;
[button setTitle:title forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:16];
button.titleLabel.textColor = [UIColor blackColor];
button.backgroundColor = [UIColor blackColor];
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[referenceView addSubview:button];
}
Once the buttons are created I am trying to access them with this function:
- (void)buttonPressed:(UIButton *)sender {
NSLog(#"button %d pressed", sender.tag+1);
}
But I don't even get to this function, I've placed a break point on the first line this buttonPressed method, but the compiler never reaches this pint, it crashes beforehand. The buttons seem to be created fine, what have I missed?
Crash Log as requested:
2014-02-05 21:27:49.242 theoryDisplay[67820:70b] -[UIScrollView buttonPressed:]: unrecognized selector sent to instance 0x8d54180
2014-02-05 21:27:49.245 theoryDisplay[67820:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIScrollView buttonPressed:]: unrecognized selector sent to instance 0x8d54180'
* First throw call stack:
(
0 CoreFoundation 0x0173b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014be8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d8903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172b90b ___forwarding___ + 1019
4 CoreFoundation 0x0172b4ee _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x014d0874 -[NSObject performSelector:withObject:withObject:] + 77
6 UIKit 0x0022e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x0022e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x003260c1 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x00326484 -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00325733 -[UIControl touchesEnded:withEvent:] + 641
11 UIKit 0x005a0c7f _UIGestureRecognizerUpdate + 7166
12 UIKit 0x0026b19a -[UIWindow _sendGesturesForEvent:] + 1291
13 UIKit 0x0026c0ba -[UIWindow sendEvent:] + 1030
14 UIKit 0x0023fe86 -[UIApplication sendEvent:] + 242
15 UIKit 0x0022a18f _UIApplicationHandleEventQueue + 11421
16 CoreFoundation 0x016c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17 CoreFoundation 0x016c41cb __CFRunLoopDoSources0 + 235
18 CoreFoundation 0x016e129e __CFRunLoopRun + 910
19 CoreFoundation 0x016e0ac3 CFRunLoopRunSpecific + 467
20 CoreFoundation 0x016e08db CFRunLoopRunInMode + 123
21 GraphicsServices 0x036e09e2 GSEventRunModal + 192
22 GraphicsServices 0x036e0809 GSEventRun + 104
23 UIKit 0x0022cd3b UIApplicationMain + 1225
24 theoryDisplay 0x0000371d main + 141
25 libdyld.dylib 0x01d7970d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException