ios - '-[UITextView autocapitalizationType]: unrecognized selector sent to instance? -


i create custom subclasses(subcustomview) of uiview when click on button , added uitextview class on subcustomview subview. when initiate uitextview use initwithframe:textcontainer: method. when used method, project crashed. when use initwithframe: method project not crashed. 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 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 uncaught exception 'nsinvalidargumentexception', reason: '-[uitextview setkeyboardappearance:]: unrecognized selector sent 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 uncaught exception of type nsexception 

you should initialize objects in proper order.

first create , attach nstextstorage, nstextcontainer , nslayoutmanager. , create uitextview prepared use nstextcontainer.

// 1. create , prepare nstextcontainer textcontainer1 = [[nstextcontainer alloc] initwithsize:cgsizemake(2, cgfloat_max)]; nsstring *samplestring=@"gprisdoingfirst ios 7.0 project"; textstorage = [[nstextstorage alloc] initwithstring:samplestring]; layoutmanager = [[customlayoutm alloc] init];//customlayoutm 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];  // 2. create uitextview stringtextview = [[uitextview alloc] initwithframe:cgrectmake(0, 0, frame.size.width, frame.size.height) textcontainer:textcontainer1];  // 3. setup uitextview stringtextview.keyboardappearance = yes; stringtextview.autoresizingmask = uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth; stringtextview.autocapitalizationtype = uitextautocapitalizationtypewords; // … 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -