我對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。這是否有意義,我該如何做到這一點?
buttonSetxy方法做什麼???你是否正確設置了框架? – mayuur
buttonSetxy僅僅是改變我的按鈕座標的另一種自定義方法。同樣,在我的主視圖控制器中進行單線編碼。 – leejhall
可以發佈buttonSetxy的代碼嗎? Cz如果你不會設置btn的框架,那麼它會添加wudnt。 – mayuur