我正在从我的 Storyboard/iOS6/ARC 应用程序中的 xib 加载叠加 View 。这个 View 有一个 ImageView 、 TextView 和一些开关。我的问题是,在自定义一些控件之后,我在尝试从 View 转换回主视图时得到 EXC_BAD_ACCESS。
我通过从我的 View Controller 创建一个实例(在 button_touchup 函数期间)并调用 UIView transitionWithView 来加载 View .我可以初始化 imageView和 text通过填充这些控件的实例函数从 VC 传递数据。这工作正常,我可以毫无问题地过渡。
当我尝试自定义开关颜色时出现问题 - 例如_toggleSwitch.thumbTintColor = [UIColor colorwithRed.....];切换显示为白色,然后在交互期间或 View 破坏时(当转换回主视图/self removeFromSuperview 时)与 bad_exec 一起崩溃。在使用实例函数转换到 View 之前,我试过这样做,我试过在 -awakeFromNib 上这样做和 -didMoveToWindow没有运气。我试过将颜色保存在类(class)的强属性中。唯一可行的是使用内置常量 - 例如_toggleSwitch.thumbTintColor = [UIColor redColor] .
如何在不崩溃的情况下自定义这些开关的外观?我什至尝试通过覆盖 View 的设置函数从我的呈现 View Controller 传递自定义 UIColor 对象,就像我将文本传递给 textfield.text 一样。和图像 imageview.image - 通过将其分配给 self.toggleswitch.thumbTintColor而且它仍然会导致糟糕的执行。如何自定义 xib 中的开关?
编辑:好的,我认为代码没有那么具有启发性,但这是叠加层
overlay.h
@property (strong, nonatomic) IBOutlet UISwitch *switchFB;
这在 -awakeFromNib/xib 中的任何其他地方都可以正常工作
Overlay.m
_switchFB.thumbTintColor = [UIColor redColor];
这会导致 exc_bad_access
_switchFB.thumbTintColor = [UIColor colorWithRed:225.0f green:152.0f blue:140.0f alpha:1.0f];
当我试图转换回 super View 时抛出异常(或者有时当与修改后的切换交互时):
- (IBAction)buttonCancelClick:(id)sender {
[UIView transitionWithView:self.superview
duration:0.5
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self removeFromSuperview];
}
completion:nil
];
}
我认为这与对创建的 UIColor 对象的内存访问有关。我在访问传递到 Overlay 以初始化文本和 ImageView 的对象时没有问题,因此我修改了初始化这些对象的设置函数(从 parentVC 调用)以初始化我的开关。这仍然会崩溃。
Overlay.h
@property (strong, nonatomic) IBOutlet UITextView *textField;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
Overlay.m
- (void)setup:(UIImage *)img text:(NSString *)txt color:(UIColor *)col
{
self.switchFB.thumbTintColor = col;
self.textField.text = txt;
self.imageView.image = img;
}
ParentVC.m
OverlayPublish *olay = [[NSBundle mainBundle] loadNibNamed:@"OverlayPublish"owner:self options:nil][0];
[olay setup:[UIImage imageNamed:@"test.png"] text:@"test txt" color:[UIColor colorWithRed:225.0f green:152.0f blue:140.0f alpha:1.0f]];
[UIView transitionWithView:self.view.superview.superview
duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^{
[self.view.superview.superview addSubview:olay];
}
completion:nil
Edit2:堆栈跟踪 - 我回到 removeFromSuperView。
thread #1: tid = 0x1c03, 0x01d8209b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=1, address=0x51019e21)
frame #0: 0x01d8209b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x0224d41c CoreFoundation`CFRelease + 108
frame #2: 0x02272e54 CoreFoundation`-[__NSArrayM dealloc] + 196
frame #3: 0x01d849ff libobjc.A.dylib`-[NSObject release] + 47
frame #4: 0x01d73927 libobjc.A.dylib
ReleaseValue std::for_each<__gnu_cxx::__normal_iterator<objc_references_support::ObjcAssociation*, std::vector<objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator<objc_references_support::ObjcAssociation> > ,ReleaseValue>(__gnu_cxx::__normal_iterator<objc_references_support::ObjcAssociation*, std::vector<objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator<objc_references_support::ObjcAssociation> > >, __gnu_cxx::__normal_iterator<objc_references_support::ObjcAssociation*, std::vector<objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator<objc_references_support::ObjcAssociation> > >, ReleaseValue) + 72 frame #5: 0x01d73632 libobjc.A.dylib_object_remove_assocations + 296frame #6: 0x01d7a7aa libobjc.A.dylib`objc_destructInstance + 60
frame #7: 0x01d7a7cf libobjc.A.dylib`object_dispose + 20
frame #8: 0x00b2601a UIKit`-[UIImage dealloc] + 217
frame #9: 0x01d849ff libobjc.A.dylib`-[NSObject release] + 47
frame #10: 0x00c0df90 UIKit`-[UIImageView dealloc] + 752
frame #11: 0x00b4199c UIKit`-[UIView release] + 93
frame #12: 0x00b497fb UIKit`-[UIView(Hierarchy) removeFromSuperview] + 190
frame #13: 0x00b43ee5 UIKit`-[UIView dealloc] + 375
frame #14: 0x00d06a01 UIKit`-[_UISwitchInternalView dealloc] + 288
frame #15: 0x00b4199c UIKit`-[UIView release] + 93
frame #16: 0x00b497fb UIKit`-[UIView(Hierarchy) removeFromSuperview] + 190
最佳答案
这是 UISwitch 特有的 SDK 中的错误。 UISwitch setThumbTintColor causing crash (iOS 6 only)?
在将 UIColor 函数变量分配给 nib 的 UISwitch thumbTintColor 属性之前调用 retain 可以解决崩溃问题。
关于ios - 初始化 NIB 负载控制 - EXC_BAD_ACCESS 销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18035637/
在我的gem中,我需要yaml并且在我的本地计算机上运行良好。但是在将我的gem推送到rubygems.org之后,当我尝试使用我的gem时,我收到一条错误消息=>"uninitializedconstantPsych::Syck(NameError)"谁能帮我解决这个问题?附言RubyVersion=>ruby1.9.2,GemVersion=>1.6.2,Bundlerversion=>1.0.15 最佳答案 经过几个小时的研究,我发现=>“YAML使用未维护的Syck库,而Psych使用现代的LibYAML”因此,为了解决
我在Rails工作并有以下类(class):classPlayer当我运行时bundleexecrailsconsole然后尝试:a=Player.new("me",5.0,"UCLA")我回来了:=>#我不知道为什么Player对象不会在这里初始化。关于可能导致此问题的操作/解释的任何建议?谢谢,马里奥格 最佳答案 havenoideawhythePlayerobjectwouldn'tbeinitializedhere它没有初始化很简单,因为你还没有初始化它!您已经覆盖了ActiveRecord::Base初始化方法,但您没有调
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我正在写一篇关于在Ruby中几乎一切都是对象的博客文章,我试图通过以下示例来展示这一点:classCoolBeansattr_accessor:beansdefinitialize@bean=[]enddefcount_beans@beans.countendend所以从类中我们可以看出它有4个方法(当然,除非我错了):它可以在创建新实例时初始化一个默认的空bean数组它可以计算它有多少个bean它可以读取它有多少个bean(通过attr_accessor)它可以向空数组写入(或添加)更多bean(也通过attr_accessor)但是,当我询问类本身它有哪些实例方法时,我没有看到默认
我去了这个website查看Rails5.0.0和Rails5.1.1之间的区别为什么5.1.1不再包含:config/initializers/session_store.rb?谢谢 最佳答案 这是删除它的提交:Setupdefaultsessionstoreinternally,nolongerthroughanapplicationinitializer总而言之,新应用没有该初始化器,session存储默认设置为cookie存储。即与在该初始值设定项的生成版本中指定的值相同。 关于