小编Mat*_*hen的帖子

目标C:为什么在创建ui对象后立即释放

许多iPhone代码示例(来自Apple等)包含如下代码:

- (void)viewDidLoad {
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

// add the top-most parent view
UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
contentView.backgroundColor = [UIColor blackColor];
self.view = contentView;
[contentView release];

levelView = [[LevelView alloc] initWithFrame:applicationFrame viewController:self];
[self.view addSubview:levelView];

calibrationView = [[CalibrationView alloc] initWithFrame:applicationFrame viewController:self];
}
Run Code Online (Sandbox Code Playgroud)

此片段来自BubbleLevel示例项目.

我的问题:为什么发布消息发送到contentView?我们在self.view中保留对contentView的引用,我们显然希望在应用程序的生命周期中使用它,而不仅仅是在此方法中.不会调用release会导致视图被释放吗?

iphone cocoa-touch objective-c

5
推荐指数
4
解决办法
773
查看次数

UIActionSheet cancelButtonTitle ipad

我正在使用UIActionSheet向用户提供一组选择.它适用于iPhone和iPod Touch,但在iPad上,"取消"选项始终隐藏.也就是说,出现带有选项的"对话框",但缺少"取消"按钮.

这是代码:

self.popupQuery = [[[UIActionSheet alloc] initWithTitle:title
                                               delegate:self
                                      cancelButtonTitle:cancelButtonTitle
                                 destructiveButtonTitle:nil
                                      otherButtonTitles:option0, option1, cancelButtonTitle, nil] autorelease];
Run Code Online (Sandbox Code Playgroud)

UIActionSheet文档状态:

cancelButtonTitle:取消按钮的标题.此按钮会自动添加到操作表中,并分配一个适当的索引,该索引可从cancelButtonIndex属性中获得.此按钮显示为黑色,表示它代表取消操作.如果您不想要取消按钮或在iPad上显示操作表,请指定nil.

我没有通过零,所以我不清楚发生了什么.这是一个错误吗?

uiactionsheet ipad ios

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

标签 统计

cocoa-touch ×1

ios ×1

ipad ×1

iphone ×1

objective-c ×1

uiactionsheet ×1