代码之家  ›  专栏  ›  技术社区  ›  Swapnil Luktuke

有没有办法创建一个没有自动释放的UIButton,并且仍然设置为uibuttonype?

  •  0
  • Swapnil Luktuke  · 技术社区  · 16 年前

    buttonWithType 。但这是一个工厂方法,将创建一个自动释放的对象。当然,我们可以这样做:

     UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 50, 30)];
    

    但在这种情况下,我无法将按钮的类型设置为 buttonType 是只读属性。

    P、 编号:

    1. 对自动释放的对象使用AutoreleasePool是一个很好的实践。但我对自动释放的对象并没有什么问题。这只是个疑问。

    谢谢, 斯瓦普尼尔

    2 回复  |  直到 16 年前
        1
  •  2
  •   Björn Marschollek    16 年前

    您可以使用初始值设定项,然后发送对象 retain 如果你还需要的话,请留言。

    我认为缺少其他初始化器的原因是,ui按钮通常作为子视图添加到某个地方,因此会收到 保持 自动发送消息。

        2
  •  2
  •   kennytm    16 年前

    +buttonWithType: 可以创建那些特殊的按钮。为什么没有 +alloc / -init some private subclass (例如UIRoundedRectButton)。

    -retain .

    theButton = [[UIButton buttonWithType:foo] retain];