我想在单击按钮时创建 uiview 的自定义子类 (SubCustomView),并在 SubCustomView 上添加 uitextview 类作为 subview 。当我启动 uitextview 时,我使用 initWithFrame:textContainer: 方法。当我使用这种方法时,项目崩溃了。当我使用 initWithFrame: 方法时,项目没有崩溃。我正在使用以下代码:
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];
错误是:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UITextView setKeyboardAppearance:]:无法识别的选择器发送到实例 0x93ab000”
首先抛出调用栈:
(
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
最佳答案
您应该以正确的顺序初始化您的对象。
首先创建并附加NSTextStorage、NSTextContainer 和NSLayoutManager。然后创建 UITextView 并准备使用 NSTextContainer。
// 1. Create and 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 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];
// 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;
// …
关于ios - '-[UITextView 自动大写类型] : unrecognized selector sent to instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158763/
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="