UISearchBar奇怪的问题

时间:2013-10-21 09:43:20

标签: iphone ios ipad ios7 uisearchbar

点击uisearchbar(ios 7)时出现此日志错误

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSBigMutableString replaceCharactersInRange:withString:]: nil argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x02c905e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x02a138b6 objc_exception_throw + 44
    2   CoreFoundation                      0x02c903bb +[NSException raise:format:] + 139
    3   Foundation                          0x0243863e -[NSBigMutableString replaceCharactersInRange:withString:] + 117
    4   Foundation                          0x02438595 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 384
    5   UIFoundation                        0x077b49f4 __71-[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:]_block_invoke + 68
    6   UIFoundation                        0x077b492f -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 121
    7   Foundation                          0x02462d46 -[NSMutableAttributedString setAttributedString:] + 90
    8   UIKit                               0x016794e2 __65-[UIFieldEditor setAttributedText:andSetCaretSelectionAfterText:]_block_invoke + 53
    9   UIFoundation                        0x077b2491 -[NSTextStorage coordinateEditing:] + 48
    10  UIKit                               0x01679375 -[UIFieldEditor setAttributedText:andSetCaretSelectionAfterText:] + 151
    11  UIKit                               0x0167969b -[UIFieldEditor setAttributedText:] + 48
    12  UIKit                               0x01c5e3f5 -[UITextField willAttachFieldEditor:] + 340
    13  UIKit                               0x016784d5 -[UIFieldEditor becomeFieldEditorForView:] + 927
    14  UIKit                               0x01c55643 -[UITextField _becomeFirstResponder] + 160
    15  UIKit                               0x0184441a -[UISearchBarTextField _becomeFirstResponder] + 98
    16  UIKit                               0x01c554a1 -[UITextField __resumeBecomeFirstResponder] + 53
    17  UIKit                               0x0184466e __45-[UISearchBarTextField _becomeFirstResponder]_block_invoke + 259
    18  UIKit                               0x01844563 -[UISearchBarTextField _becomeFirstResponder] + 427
    19  UIKit                               0x016d2585 -[UIResponder becomeFirstResponder] + 400
    20  UIKit                               0x015d5d0b -[UIView(Hierarchy) becomeFirstResponder] + 114
    21  UIKit                               0x01c550e3 -[UITextField becomeFirstResponder] + 51
    22  UIKit                               0x018415b0 -[UISearchBar(UISearchBarStatic) becomeFirstResponder] + 42
    23  UIKit                               0x0183f9ef -[UISearchBar tappedSearchBar:] + 57
    24  UIKit                               0x018f0f8c _UIGestureRecognizerSendActions + 230
    25  UIKit                               0x018efc00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
    26  UIKit                               0x018f166d -[UIGestureRecognizer _delayedUpdateGesture] + 60
    27  UIKit                               0x018f4bcd ___UIGestureRecognizerUpdate_block_invoke + 57
    28  UIKit                               0x018f4b4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
    29  UIKit                               0x018eb248 _UIGestureRecognizerUpdate + 199
    30  UIKit                               0x015b7d4a -[UIWindow _sendGesturesForEvent:] + 1291
    31  UIKit                               0x015b8c6a -[UIWindow sendEvent:] + 1030
    32  UIKit                               0x0158ca36 -[UIApplication sendEvent:] + 242
    33  UIKit                               0x01576d9f _UIApplicationHandleEventQueue + 11421
    34  CoreFoundation                      0x02c198af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    35  CoreFoundation                      0x02c1923b __CFRunLoopDoSources0 + 235
    36  CoreFoundation                      0x02c3630e __CFRunLoopRun + 910
    37  CoreFoundation                      0x02c35b33 CFRunLoopRunSpecific + 467
    38  CoreFoundation                      0x02c3594b CFRunLoopRunInMode + 123
    39  GraphicsServices                    0x0302d9d7 GSEventRunModal + 192
    40  GraphicsServices                    0x0302d7fe GSEventRun + 104
    41  UIKit                               0x0157994b UIApplicationMain + 1225
    42  Mobile4Job                          0x00002b5d main + 141
    43  libdyld.dylib                       0x03451725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException

我从来没有看到类似的东西,我无法修复它。

2 个答案:

答案 0 :(得分:0)

从堆栈跟踪中,假设您要重建在搜索栏中输入的文本,并尝试用其他字符串替换范围中的字符串,并且您的其他字符串似乎是nil。请检查您使用的字符串,其中一个是nil

答案 1 :(得分:0)

我发现了问题,我有一个UITextfield实现:

@implementation UITextField (clearCustomButton)
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}
- (void)awakeFromNib{
    self.clearButtonMode = UITextFieldViewModeWhileEditing;
}
- (CGRect)clearButtonRectForBounds:(CGRect)bounds{
    return CGRectMake(bounds.size.width - 20, (bounds.size.height - 14)/2, 14, 14);
}
@end

如果我删除:

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

它有效。顺便说一句,感谢@danypata

相关问题