嗨,我很新的iphone開發。我是java背景developer.So我的方法就像java。如何在iPhone中使用一個參數從另一個全局函數調用全局函數?
這裏我的要求是,我想從每個視圖控制器調用一個全局函數。 並從那裏我傳遞self.navigationController作爲參數。在那個函數中,我添加了一些buton。當用戶點擊該按鈕時,它應該調用一個更多的功能,它應該攜帶與參數相同的對象。
請給我指導。我嘗試如下,但它正顯示出在編譯時
Utilities.m
+(void)setBacKButton:(UINavigationController *)navigationController
{
for(UIButton *btn in navigationController.navigationBar.subviews){
if([btn isKindOfClass:[UIButton class]]){
[btn removeFromSuperview];
}
}
UIButton *btn2=[UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame=CGRectMake(708, 0, 50, 54);
[btn2 setImage:[UIImage imageNamed:@"btn_back.png"] forState:0];
[btn2 setImage:[UIImage imageNamed:@"btn_back_h.png"] forState:UIControlStateSelected];
// here i need to call bellow function when click on this button
//[btn2 addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside];
[navigationController.navigationBar addSubview:btn2];
}
+(void)gotoBack:(UINavigationController *)navigationController
{
[navigationController popViewControllerAnimated:YES];
}
錯誤,我調用該函數從我的ViewController作爲
[Utilities setBacKButton:self.navigationController];
請告訴我如何才能做到這一點
謝謝你的重播,但我想實現一種方法來彈出屏幕。爲此,我需要navigationcontroler對象,所以我如何獲得導航控制器對象? –
只是在您的appdelegate中初始化一個導航控制器對象,並將您的視圖控制器推送到該導航控制器。這是作爲基於導航的項目的基本原理。因此,您只需要在該功能中使用視圖控制器對象並將其推送到appdelegate導航控制器。 – hacker