Objective C - 初始化对象时通过方法参数传递对象名称的问题
我对 Objective C 很陌生,正在尝试创建一种仅用一行代码初始化对象(更准确地说是按钮对象)的方法...我的方法声明是...
- (void)buttonDeclaration: (UIButton *)mButton :(int)xloc :(int)yloc :(int)bWidth :(int)bHeight
: (NSString *)sImage :(UIViewController *)mView :(SEL)mSelector
{
mButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self buttonSetxy:mButton :xloc :yloc :bWidth :bHeight];
[mButton setBackgroundImage:[UIImage imageNamed:sImage] forState:UIControlStateNormal];
[mView.view addSubview:mButton];
}
我的方法调用是...
[...buttonDeclaration:newButton :40 :65 :80 :65...]
但是 添加
[newButton setHidden:FALSE];
当我尝试在调用该方法后 时,它什么也不做。我不确定正确的术语是什么,但对象名称应该是 newButton 而不是 mButton。这有意义吗?我该如何实现这一目标?
I am very new to Objective C and am trying to create a method for initializing an object (button object to be more precise) with only one line of code... My method declaration is...
- (void)buttonDeclaration: (UIButton *)mButton :(int)xloc :(int)yloc :(int)bWidth :(int)bHeight
: (NSString *)sImage :(UIViewController *)mView :(SEL)mSelector
{
mButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self buttonSetxy:mButton :xloc :yloc :bWidth :bHeight];
[mButton setBackgroundImage:[UIImage imageNamed:sImage] forState:UIControlStateNormal];
[mView.view addSubview:mButton];
}
My method call is...
[...buttonDeclaration:newButton :40 :65 :80 :65...]
but when I try to add
[newButton setHidden:FALSE];
after my call to the method it does nothing. I'm not sure what the proper term is, but the object name should be newButton not mButton. Does this make sense and how do I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,objective c 中声明方法的方式是不同的。
当您声明具有多个参数的方法时,它应该是这样的。
所以你的方法将被声明为
现在您将通过以下方式调用此方法
如果你想隐藏你的按钮,只需写
Actually the way methods are declared in objective c is different.
When you declare method with multiple arguments then it should be like this.
so ur method will be declared like
Now you will be calling this method by
and if you want to hide your button, just write