标签: init

如何创建自定义UIView?

我已经创建了一个UIView子类和相应的xib文件,其中我已经布置了一些UILabels和UIImageViews.我想将这个自定义UIView的多个副本放入UIViewController.

当我这样做时,它们在界面构建器中显示为空白,并且在应用程序加载时不会显示.我需要在UIView子类上实现哪些方法才能使其工作?

iphone init xib uiview custom-view

0
推荐指数
1
解决办法
6115
查看次数

不要让使用 - (id)init; 方法

我正在为iPhone 3.1.3开发一款应用程序.

我有以下课程:

@interface Pattern : NSObject {

    NSMutableArray* shapes;
    NSMutableArray* locations;
    CGSize bounds;
}
@property (nonatomic, retain, readonly) NSMutableArray* shapes;
@property (nonatomic, retain, readonly) NSMutableArray* locations;

- (id) initWithNumShapes:(int)numShapes screenSize:(CGSize)screenSize;
- (void) addObject:(Object2D*) newObject;

@end
Run Code Online (Sandbox Code Playgroud)

我不想让程序员使用,-(id)init;因为我需要在每次初始化时设置我的字段(形状,位置,边界).

我不想让程序员使用它:

Pattern* myPattern = [[Pattern alloc] init];
Run Code Online (Sandbox Code Playgroud)

我知道如何实现:

- (id) initWithNumShapes:(int)numShapes screenSize:(CGSize) screenSize{
    if (self = [super init]) {
        shapes = [NSMutableArray arrayWithCapacity:numShapes];
        locations = [NSMutableArray arrayWithCapacity:numShapes];
        bounds = screenSize;
    }
    return (self);
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

objective-c init iphone-sdk-3.0

0
推荐指数
1
解决办法
803
查看次数

如何从超类方法调用python子类方法?

我有以下类型的超类/子类设置:

class SuperClass(object):
    def __init__(self):
        self.do_something() # requires the do_something method always be called

    def do_something(self):
        raise NotImplementedError

class SubClass(SuperClass):
    def __init__(self):
        super(SuperClass, self).__init__() # this should do_something 

    def do_something(self):
        print "hello"
Run Code Online (Sandbox Code Playgroud)

我希望SuperClass init始终调用一个尚未实现的do_something方法.我正在使用python 2.7.也许ABC可以做到这一点,但它有另一种方式吗?

谢谢.

python subclass init abc super

0
推荐指数
1
解决办法
2544
查看次数

Arch Linux上的systemd

所以我正在尝试systemd在Arch Linux机器上使用.

阅读文档,我看到 - https://wiki.archlinux.org/index.php/Systemd#Installation

add init=/bin/systemd to your kernel cmdline in your bootloader
Run Code Online (Sandbox Code Playgroud)

这到底是什么意思?

我并不是全新的Linux,但我在理解如何完成这项工作时遇到了一些麻烦.任何阐述都非常感谢!

init linux-kernel archlinux

0
推荐指数
1
解决办法
3325
查看次数

为什么python中的__init__失败

我正在使用python2.7来定义这样的函数

def foo(*args, **kwargs):
    print 'args = ', args
    print 'kwargs = ', kwargs
    print '---------------------------------------'
Run Code Online (Sandbox Code Playgroud)

并通过调用foo(3),输出如下:

args =  (3,)
kwargs =  {}
Run Code Online (Sandbox Code Playgroud)

这是所希望的.

但是对于__init__参数与foo相同的类中的函数,我无法通过调用实例化类PersonPerson(3)

def Person():
    def __init__(self, *args, **kwargs):
        print args
        print kwargs
x = Person(3)
Run Code Online (Sandbox Code Playgroud)

输出是

    x = Person(3)
TypeError: Person() takes no arguments (1 given)
Run Code Online (Sandbox Code Playgroud)

这让我很困惑,我错过了什么吗?

python class init

0
推荐指数
1
解决办法
111
查看次数

initWithNibName没有实现超类 - Swift

我正在尝试实现Objective-C equiv.下面用nib调用视图控制器时.

目标C:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.modalPresentationStyle = UIModalPresentationCustom;
        self.transitioningDelegate = self;
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止迅速的地方:

override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

    self.modalPresentationStyle = UIModalPresentationStyle.Custom
    self.transitioningDelegate = self
}
Run Code Online (Sandbox Code Playgroud)

但是我一直收到这个错误:

Class "ViewController" does not implement its superclass's required members
Run Code Online (Sandbox Code Playgroud)

我以为上面的init方法是否需要成员?

编辑 - 进入下面的更多细节: 类不实现其超类的必需成员

objective-c init ios swift

0
推荐指数
1
解决办法
5963
查看次数

Pygame.init() 不工作

我成功下载了 pygame 但现在当我这样做时:

import pygame
pygame.init()
size =  [400, 400]

pygame.display.set_mode(size)
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module> pygame.init AttributeError:
'module' object has no attribute 'init'
Run Code Online (Sandbox Code Playgroud)

没有什么对我有用。请帮我使用initdisplay

我在用

python pygame init

0
推荐指数
1
解决办法
1万
查看次数

在Swift中进行子类化时了解init()

从已经具有初始化程序的类继承时,如何添加自定义初始值设定项?

我所拥有的是一个Vehicle有一个参与的itializer 的类name.我想要做的是继承这个Vehicle类,为新类创建另一个初始化器,但继续使用现有的初始化器.

基类(这里没问题):

class Vehicle{
    var make:String
    init(make:String){
     self.make = make
    }
}
Run Code Online (Sandbox Code Playgroud)

新类(不起作用):

// Not sure how to structure this class     
class Car:Vehicle {
    var engine:Double

    override init(){
        super.init()
    }

    init(engine:Double){
        self.engine = engine
    }
}
Run Code Online (Sandbox Code Playgroud) 这就是我希望能够做到的...重新使用现有的初始化程序和新的初始化程序.
let cobalt = Car(make:"Chevy" engine: 2.5)
Run Code Online (Sandbox Code Playgroud)

inheritance subclass init swift

0
推荐指数
1
解决办法
272
查看次数

Debian 映像 - /sbin/init 未找到

我正在尝试启动 Debian 映像,并/sbin/init通过 molecular 进行 ansible 角色测试。

是的,我知道,除非您确实有这样做的用例,否则不应/sbin/init在容器中启动。使用 molecular,我可以在 docker 容器中测试我的 ansible 角色。因此我需要/sbin/init跑步。

当我执行时

docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro debian:9 /sbin/init

docker: Error response from daemon: OCI runtime create failed: container_linux.go:346:
starting container process caused "exec: \"/sbin/init\": stat /sbin/init: no such file 
or directory": unknown.
Run Code Online (Sandbox Code Playgroud)

然而,在 debian:8 下它工作得很好。

docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro debian:8 /sbin/init
Run Code Online (Sandbox Code Playgroud)

奇迹般有效。

Debian 是否已切换到新的启动过程?发生了什么变化?

debian init docker molecule

0
推荐指数
1
解决办法
1万
查看次数

python如何在子类中启动一个值?

我有以下代码:

class Vehicle:
    def __init__(self, name=None, color='Red', make='Toyota'):
        self._name = name 
        self._color = color
        self._make = make

    @property
    def name(self):
        if self._name is None:
            return 'name is none'
        return self._name

    @name.setter
    def name(self, value):
        self._name=value   

    def getColor(self):
        return self._color

    def getMake(self):
        return self._make    

class Car(Vehicle):
    def __init__(self, mode='Running', *args, **kwargs):
        super().__init__(self,  *args, **kwargs)
        self._mode=mode

    def getMode(self):
        return self._mode
Run Code Online (Sandbox Code Playgroud)

我想启动汽车的名称,但是以下都不起作用。有没有简单的方法来做到这一点?

mycar=Car('Corolla')
mycar=Car(name='Corolla')
Run Code Online (Sandbox Code Playgroud)

python inheritance subclass init args

0
推荐指数
1
解决办法
33
查看次数