作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题可能看起来很愚蠢,只是在 Objective-C 的一些基础知识中遇到了问题。我知道 Objective-C 只支持按值传递,但是我的要求需要传递地址。我有一个 UIButton 成员变量 (iVar),我将它们传递给一个函数,并尝试使用如下参数在函数内部分配 init...
函数调用:
[self create_button : ivar_btn];
定义:
- (void) create_button : (UIButton*) button
{
// Create button
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"00/00/0000" forState:UIControlStateNormal];
[self.add_scroll_view addSubview:button];
}
那么在 Objective-C 中没有通过引用传递,我该如何处理这种情况?
如果理解有误,请指正。
注意:创建按钮是一个通用代码,我一直在使用它在运行时根据需求创建按钮。
谢谢
最佳答案
这是无用的实现,我还没有尝试过,但仍然如此。
UIButton *ivar_btn = nil;
[self create_button : &ivar_btn];
- (void) create_button : (UIButton**) button
{
// Create button
*button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[*button setTitle:@"00/00/0000" forState:UIControlStateNormal];
[self.add_scroll_view addSubview:*button];
}
关于iphone - 如何将 UIButton 传递给函数并在那里创建...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17564480/
我是一名优秀的程序员,十分优秀!