-2

The application crashes at replaceobjectatindex . The clickedbuttonpath.row returns nil value . Need help .

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
if (textField.text.length>0)
 { 
UITableViewCell *clickedCell = (UITableViewCell *)[[textField superview] superview];
 NSIndexPath *clickedButtonPath = [addSizesTableView_ indexPathForCell:clickedCell]; 
if (textField.tag==6) 
{ 
[textDic setObject:textField.text forKey:clickedButtonPath]; 
[orderArr replaceObjectAtIndex:clickedButtonPath.row withObject:textField.text];

This is the crash log which am getting .

'NSInvalidArgumentException', reason: '* setObjectForKey: key cannot be nil' * First throw call stack: ( 0 CoreFoundation 0x0000000106d1ef35 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001062acbb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000106c25998 -[__NSDictionaryM setObject:forKey:] + 968 3 BookMyStock 0x0000000103559ac0 -[AddSizesOfColors textFieldDidEndEditing:] + 368 4 UIKit 0x0000000105289549 -[UITextField _resignFirstResponder] + 382 5 UIKit 0x0000000104ccc4f5 -[UIResponder resignFirstResponder] + 236 6 UIKit 0x00000001052892d4 -[UITextField resignFirstResponder] + 114 7 UIKit 0x0000000105295953 -[UIView(UITextField) endEditing:] + 173 8 BookMyStock 0x0000000103557c2d -[AddSizesOfColors addTFTotheView] + 285 9 UIKit 0x0000000104b568be -[UIApplication sendAction:to:from:forEvent:] + 75 10 UIKit 0x0000000104c5d410 -[UIControl _sendActionsForEvents:withEvent:] + 467 11 UIKit 0x0000000104c5c7df -[UIControl touchesEnded:withEvent:] + 522 12 UIKit 0x0000000104b9c308 -[UIWindow _sendTouchesForEvent:] + 735 13 UIKit 0x0000000104b9cc33 -[UIWindow sendEvent:] + 683 14 UIKit 0x0000000104b699b1 -[UIApplication sendEvent:] + 246 15 UIKit 0x0000000104b76a7d _UIApplicationHandleEventFromQueueEvent + 17370 16 UIKit 0x0000000104b52103 _UIApplicationHandleEventQueue + 1961 17 CoreFoundation 0x0000000106c54551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 18 CoreFoundation 0x0000000106c4a41d __CFRunLoopDoSources0 + 269 19 CoreFoundation 0x0000000106c49a54 __CFRunLoopRun + 868 20 CoreFoundation 0x0000000106c49486 CFRunLoopRunSpecific + 470 21 GraphicsServices 0x0000000108bdc9f0 GSEventRunModal + 161 22 UIKit 0x0000000104b55420 UIApplicationMain + 1282 23 BookMyStock 0x0000000103492913 main + 115 24 libdyld.dylib 0x0000000107c7e145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

  • r u checkd the which index u get – Anbu.Karthik Feb 03 '15 at 07:49
  • please post a crashlog, otherwise no one will be able to help you :) – nburk Feb 03 '15 at 07:50
  • Welcome to Stack Overflow. Please refer to the Help Center on how to ask a question with good chances of being answered (http://stackoverflow.com/help/how-to-ask). Specifically, include error messages that would allow better undestanding of the issue. – h7r Feb 03 '15 at 08:10
  • This code works fine with ios 7 but crashes in ios 8 . – Nikilicious Feb 03 '15 at 08:52

1 Answers1

0

[[textField superview] superview] returns nil, incase of iOS 8, whereas in iOS 7 it returns some value. As suggested in below link, don't rely on view hierarchy.

You can check this link Getting UITableViewCell from its superview iOS 7 issue

You can try below like structure

CGPoint subviewPosition = [textField convertPoint:CGPointZero toView:self.tableView];
NSIndexPath* clickedButtonPath = [addSizesTableView_ indexPathForRowAtPoint:subviewPosition];
Community
  • 1
  • 1
Vinoth Kumar
  • 156
  • 8
  • Thanks Vinoth . I tried your code but the problem is that the application is crashing at [orderArr replaceObjectAtIndex:clickedButtonPath.row withObject:textField.text]; – Nikilicious Feb 03 '15 at 11:57
  • Can you keep a breakpoint or NSLog and see clickedCell is getting a non nil value in iOS 8.? Because if clickedCell is nil, then clickedButtonPath will be nil, then clickedButtonPath.row will be nil. – Vinoth Kumar Feb 03 '15 at 12:02
  • UITableViewCell *clickedCell = (UITableViewCell *)[[textField superview] superview]; – Vinoth Kumar Feb 03 '15 at 12:09
  • clickedCell is not giving a nil value . – Nikilicious Feb 03 '15 at 12:24