草庐IT

admin_init

全部标签

ios - 从初始化器返回之前不调用 Super.init

我尝试为我的UITableViewCell类提供自定义启动器,但我无法弄清楚我做错了什么。这是我的代码:init(dataObject:[NSManagedObject]!,objectAttributeValues:[String]!,placeholder:String!,segmentedControl:UISegmentedControl?,cellHeight:CGRect,cellWidth:CGRect){self.dataObject=dataObjectself.Placeholder.text=placeholderself.objectAttributeValue

ios - 子类化 UIView。 init 方法永远不会被调用

我在界面生成器上有一个UIView。在我的ViewController中,我有一个IBOutletMyUIView,它指向界面生成器上的UIView。我将UIView的类更改为“MyUIView”(自定义UIView类),但似乎没有init方法子类被解雇。我做错了什么? 最佳答案 您需要先调用initWithCoder而不是init然后调用init为:-(id)initWithCoder:(NSCoder*)aDecoder{if((self=[superinitWithCoder:aDecoder])){[selfbaseClas

ios - 如何禁止 NSObject 中的基本 init 方法

我想强制用户使用我自己的初始化方法(例如-(id)initWithString:(NSString*)foo;)而不是基本的[[myObjectalloc]init];。我该怎么做? 最佳答案 这里的所有其他答案都已过时。现在有一种方法可以正确地做到这一点!虽然当有人调用您的方法时很容易在运行时崩溃,但编译时检查会更可取。幸运的是,这在Objective-C中已经有一段时间了。使用LLVM,您可以像这样在类中声明任何方法不可用-(void)aMethod__attribute__((unavailable("Thismethodis

ios - Swift : use of 'self' in method call before super. init初始化自编译报错

我创建了一个处理音频录制/播放的自定义类,并在该类中放置了一个Protocol。我在UIViewController类中实现了Protocol并为我的AudioHelper类调用了我的setDelegate方法。我收到一个与我的init()有关的编译错误。不确定如何消除错误:在super.init初始化self之前在方法调用“setupAudioSession”中使用“self”overrideinit(){setupAudioSession()super.init()}如何解决此错误?为什么我必须覆盖init()?我的AudioHelper类importFoundationimpor

iOS:ViewController 的 -init 和 -viewLoad 有什么区别?

我不知道在什么位置设置NavigationBar的tintColor或我的ViewController的标题是正确的。它也适用于-init方法和-viewLoad方法。执行此操作的“最佳实践”或“正确方法”是什么?其中之一有任何优势吗? 最佳答案 init方法(是的,不止一个)是初始化UIViewController的地方。因此,这是您为UIViewController而不是它的View做事的地方。如果您使用nib加载您的View,那么设置任何属性的最佳位置是viewDidLoad方法。此方法在nib加载后被调用。如果您使用load

ios - UICollectionViewCell 子类 init 从不运行

我像这样在viewDidLoad中添加了一个CollectionView......self.collectionView=[[UICollectionViewalloc]initWithFrame:CGRectMake(0,0,10,10)collectionViewLayout:flowLayout];self.collectionView.delegate=self;self.collectionView.dataSource=self;self.collectionView.backgroundColor=[UIColorwhiteColor];[self.collection

iOS: UIView 子类 init 或 initWithFrame:?

我做了一个UIView的子类,它有一个固定的框架。那么,我可以只覆盖init而不是initWithFrame:吗?例如:-(id)init{if((self=[superinitWithFrame:[[UIScreenmainScreen]bounds]])){self.backgroundColor=[UIColorclearColor];}returnself;}-initWithFrame:的Xcode文档说:“如果您以编程方式创建View对象,则此方法是UIView类的指定初始化程序。子类可以覆盖此方法方法来执行任何自定义初始化,但必须在其实现开始时调用super。”“指定初始

ios - "pod init"创建错误 "You need at least git version 1.8.5 to use CocoaPods"

我无法在我的系统中安装任何pod。因此,我从我的Mac中删除了cocoapods,然后重新安装了它。该过程是成功的,但是当我运行命令podinit时,终端中出现以下错误:`verify_minimum_git_version!':[!]Youneedatleastgitversion1.8.5touseCocoaPods(Pod::Informative)from/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.1/lib/cocoapods/command.rb:49:in`run'from/Library/Ruby/Gems/2.0.0/gem

ios - 使用 GCC 时为 "Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo."

在尝试编译我的C程序时,运行以下命令:gccpthread.c-opthread返回:AgreeingtotheXcode/iOSlicenserequiresadminprivileges,pleasere-runasrootviasudo.我的代码无法编译。为什么会发生这种情况,我该如何解决这个问题? 最佳答案 打开Xcode,接受新的用户协议(protocol)。发生这种情况是因为下载了新版本的Xcode,但未接受新协议(protocol)。 关于ios-使用GCC时为"Agree

mysql - php_network_getaddresses : getaddrinfo failed error in Docker's adminer

我在使用laravel5/mysql应用程序访问我的docker容器中的管理员时遇到问题。我得到了错误:SQLSTATE[HY000][2002]php_network_getaddresses:getaddrinfofailed:Namedoesnotresolve我的docker-compose.yml:version:'3'services:votes_app:build:context:./webdockerfile:Dockerfile.ymlcontainer_name:votes_app_containerenvironment:-APACHE_RUN_USER=#100