gpt4 book ai didi

ios - 为什么指针无法取回新值? iOS

转载 作者:行者123 更新时间:2023-11-28 19:45:59 25 4
gpt4 key购买 nike

问题如下:

@property(nonatomic,strong)UIButton *startBtn;

-(void)createView
{
int btnW = 22;
int btnH = 14;


self.startBtn = [[UIButton alloc] init];
NSLog(@"%@",self.startBtn);//log1

[self createButton:@selector(startBtnDidClicked:) frame:CGRectMake( screenW - btnW , screenH/2 - btnH, btnW, btnH) addedto:self.view andEqualToBtn:self.startBtn];

//quetion is here
NSLog(@"%@",self.startBtn);//log5 --same as log1 (the expected value should be different from log1)
}

- (void)createButton:(SEL)action frame:(CGRect)frame addedto:(UIView *)parentView andEqualToBtn:(UIButton *)button
{

UIButton *btn = [[UIButton alloc] initWithFrame:frame];

NSLog(@"%@",btn); //log2
button = btn;
NSLog(@"%@",button); // log3 --same as log2

NSLog(@"%@",self.startBtn); //log4 -- same as log1
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
[parentView addSubview:button];
}

我想取回值,所以预期的结果应该是:log5 应该与 log1 不同,但与 log2 相同。我在想为什么log3可以这样,但是指针不能取出新值?

非常感谢您的帮助!

最佳答案

当您声明 andEqualToBtn:(UIButton *)button 时,您获得的是指针的值,而不是对实际指针的引用。

如果您需要更改指针指向的内容,您需要 andEqualToBtn:(UIButton **)button 然后修复您的参数和赋值以匹配。

关于ios - 为什么指针无法取回新值? iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32158827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com