我是非常新的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。这有意义吗?我该如何做到这一点?
实际上在objective c中声明方法的方式是不同的。
当你声明一个有多个参数的方法时,它应该是这样的
- (void) myMethod:(int) firstNum seconargument:(int) seconnum
所以你的方法将被声明为
- (void)buttonDeclaration: (UIButton *)mButton xPosition:(int)xloc yPosition:(int)yloc Width:(int)bWidth height:(int)bHeight imageName: (NSString *)sImage myView:(UIViewController *)mView selector:(SEL)mSelector
现在你将通过
调用这个方法[self buttonDeclaration: myBtn xPosition: 5 yPosition: 10 width: 5 height: 10以此类推.......]
如果你想隐藏你的按钮,只需写
myBtn。