应用程序在replaceobjectatindex崩溃。 clickedbuttonpath.row返回nil值。需要帮助。
- (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];
这是崩溃日志。
' NSInvalidArgumentException',原因:' * setObjectForKey:key不能为nil' * 第一次抛出调用堆栈: ( 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:以NSException类型的未捕获异常终止
答案 0 :(得分:0)
[[textField superview] superview]返回iOS 8的nil,而在iOS 7中它返回一些值。如下面的链接所示,不要依赖于视图层次结构。
您可以查看此链接Getting UITableViewCell from its superview iOS 7 issue
你可以尝试下面的结构
CGPoint subviewPosition = [textField convertPoint:CGPointZero toView:self.tableView];
NSIndexPath* clickedButtonPath = [addSizesTableView_ indexPathForRowAtPoint:subviewPosition];