I would like to create custom subclasses(SubCustomView) of uiview when click on button and added uitextview class on SubCustomView as subview. when i initiate uitextview i use initWithFrame:textContainer:
method. when i used this method, the project is crashed. When i use initWithFrame:
method the project is not crashed. I am using following code:
textContainer1 = [[NSTextContainer alloc] initWithSize:CGSizeMake(2, CGFLOAT_MAX)];
stringTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) textContainer:textContainer1];
//stringTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
stringTextView.keyboardAppearance = YES;
stringTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
stringTextView.scrollEnabled = YES;
stringTextView.backgroundColor = [UIColor redColor];
stringTextView.autocapitalizationType = UITextAutocapitalizationTypeWords;
stringTextView.delegate = self;
[self addSubview:stringTextView];
[stringTextView becomeFirstResponder];
NSString *sampleString=@"GPRisdoingfirst ios 7.0 project";
textStorage = [[NSTextStorage alloc] initWithString:sampleString];
layoutManager = [[CustomLayoutM alloc] init];//CustomLayoutM is subclass of `NSLayoutManager`
[textStorage addLayoutManager:layoutManager];
[textStorage addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:30.0] range:NSMakeRange(0, [textStorage length])];
[layoutManager addTextContainer:textContainer1];
The error is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextView setKeyboardAppearance:]: unrecognized selector sent to instance 0x93ab000'
First throw call stack:
(
0 CoreFoundation 0x019706f4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x016f08b6 objc_exception_throw + 44
2 CoreFoundation 0x01a0d983 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 libobjc.A.dylib 0x01702959 -[NSObject forwardInvocation:] + 68
4 CoreFoundation 0x019607ea ___forwarding___ + 458
5 CoreFoundation 0x019605fe _CF_forwarding_prep_0 + 14
6 UIKit 0x006ff4b3 -[UITextInputTraits takeTraitsFrom:] + 1075
7 UIKit 0x006ffc2b +[UITextInputTraits traitsByAdoptingTraits:] + 83
8 UIKit 0x0063a659 -[UIKeyboardImpl takeTextInputTraitsFromDelegate] + 177
9 UIKit 0x0063acbb -[UIKeyboardImpl setDelegate:force:] + 1040
10 UIKit 0x0063a8a6 -[UIKeyboardImpl setDelegate:] + 48
11 UIKit 0x008e535d -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 640
12 UIKit 0x005c0d5a -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 287
13 UIKit 0x005c064b -[UIResponder becomeFirstResponder] + 550
14 UIKit 0x004c4dab -[UIView(Hierarchy) becomeFirstResponder] + 114
15 UIKit 0x00b33e69 -[UITextView becomeFirstResponder] + 79
16 UIKit 0x004c4df8 -[UIView(Hierarchy) deferredBecomeFirstResponder] + 67
17 UIKit 0x004c4e8c -[UIView(Hierarchy) _promoteSelfOrDescendantToFirstResponderIfNecessary] + 115
18 UIKit 0x004c514e __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 224
19 Foundation 0x014a453c -[NSISEngine withBehaviors:performModifications:] + 107
20 Foundation 0x01334395 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
21 UIKit 0x004c4fcd -[UIView(Hierarchy) _postMovedFromSuperview:] + 313
22 UIKit 0x004d00d1 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1847
23 UIKit 0x004c35c1 -[UIView(Hierarchy) addSubview:] + 56
24 PracticeiOS7 0x000085a6 -[TextCurveView createTextViewMethod] + 518
25 PracticeiOS7 0x00008a9d -[TextCurveView panMethod:] + 1101
26 UIKit 0x007de61c _UIGestureRecognizerSendActions + 230
27 UIKit 0x007dd290 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
28 UIKit 0x007decfd -[UIGestureRecognizer _delayedUpdateGesture] + 60
29 UIKit 0x007e225d ___UIGestureRecognizerUpdate_block_invoke + 57
30 UIKit 0x007e21de _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
31 UIKit 0x007d88d8 _UIGestureRecognizerUpdate + 199
32 UIKit 0x004a6e9a -[UIWindow _sendGesturesForEvent:] + 1291
33 UIKit 0x004a7dba -[UIWindow sendEvent:] + 1030
34 UIKit 0x0047bb86 -[UIApplication sendEvent:] + 242
35 UIKit 0x0046635f _UIApplicationHandleEventQueue + 11421
36 CoreFoundation 0x018f996f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
37 CoreFoundation 0x018f92fb __CFRunLoopDoSources0 + 235
38 CoreFoundation 0x019163ce __CFRunLoopRun + 910
39 CoreFoundation 0x01915bf3 CFRunLoopRunSpecific + 467
40 CoreFoundation 0x01915a0b CFRunLoopRunInMode + 123
41 GraphicsServices 0x030fca27 GSEventRunModal + 192
42 GraphicsServices 0x030fc84e GSEventRun + 104
43 UIKit 0x00468f0b UIApplicationMain + 1225
44 PracticeiOS7 0x00009b8d main + 141
45 libdyld.dylib 0x02dec725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
You should initialize your objects in proper order.
First create and attach
NSTextStorage
,NSTextContainer
andNSLayoutManager
. And then createUITextView
with prepared to useNSTextContainer
.