Objective c 目标C-初始化对象时通过方法参数传递对象名称的问题

Objective c 目标C-初始化对象时通过方法参数传递对象名称的问题,objective-c,object,methods,parameters,Objective C,Object,Methods,Parameters,我对Objective C非常陌生,我正在尝试创建一种方法,用一行代码初始化一个对象(更准确地说是button对象)。。。我的方法声明是 - (void)buttonDeclaration: (UIButton *)mButton :(int)xloc :(int)yloc :(int)bWidth :(int)bHeight : (NSString *)sImage :(UIViewController *)mView :(SEL)mSele

我对Objective C非常陌生,我正在尝试创建一种方法,用一行代码初始化一个对象(更准确地说是button对象)。。。我的方法声明是

- (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。这有意义吗?我如何做到这一点?

实际上,在目标c中声明方法的方式是不同的

当您用多个参数声明方法时,应该是这样的

  • (void)myMethod:(int)firstNum secondArgument:(int)secondNum
因此,您的方法将声明为

  • (void)按钮声明:(UIButton*)mButton xPosition:(int)xloc yPosition:(int)yloc Width:(int)bWidth height:(int)bHeight imageName:(NSString*)sImage myView:(UIViewController*)MVView选择器:(SEL mSelector
现在您将通过调用此方法

[自选按钮说明:myBtn X位置:5 Y位置:10宽度:5高度:10等等……]

如果你想隐藏你的按钮,只需写下

myBtn.hidden=是


这只会更改名称,但不会产生任何其他效果。我同意使用未命名的参数是一件坏事。buttonSetxy方法做什么???您是否正确设置了框架?buttonSetxy只是另一个自定义方法,它只更改我的按钮的坐标。同样,对于我的主viewcontroller中的单行编码,您可以发布buttonSetxy的代码吗?Cz如果你不会设置btn的框架,那么它就不会被添加。