2011-11-04 67 views
0

我是Iphone應用程序的新程序員。我工作動態不使用nib文件。 我想將值從一個視圖控制器傳遞給另一個。在初始化方法中傳遞值

firstView.m

這兩個值

cell.textLabel.text 
cell.detailTextLabel.text 

我想在TabBarSearchThirdView init方法來傳遞..

TabBarSearchThirdView *thirdView=[[TabBarSearchThirdView alloc]init]; 
[myView addSubview:thirdView.view]; 

TabBarSearchThirdView.m文件。

-(id)init 
{ 
firstVariable=.......... 
secondVariable=.......... 
} 

希望你能理解我的問題。如果可能,請給我一點代碼或建議 並給我一個簡單而好的表格視圖教程的鏈接。如果可能的話

在此先感謝

回答

3

你應該聲明這樣一個

- (id)initWithText:(NSString *)aText andDetail:(NSString *)aDetail{ 
    self = [super init]; 

    if(self){ 
     firstVariable = aText; 
     secondVariable = aDetail; 
    } 

    return self; 
} 
+0

感謝...我想這 – GauravBoss

+0

@ Luca..thanks。 ...你的代碼工作正常...只有這個警告來...你能建議我......爲什麼警告來了------->(消息沒有匹配的方法簽名 – GauravBoss

+0

你是否在界面中聲明瞭簽名代碼(.h)? –

0

一個新的init方法從1個控制器將值傳遞到另一個控制器,你必須定義在AppDelegate類2個變量,財產和合成。例如NSstring * firstVariable和NSString * secondVariable,並提及其屬性和綜合。

並在您的代碼後 TabBarSearchThirdView * thirdView = [[TabBarSearchThirdView alloc] init];

MyAppnameDelegate AppDel = (MyAppnameAppDelegate*)[[UIApplication sharedApplication]delegate]; 

// MyAppnameDelegate是你appdelegete類,因此通過您的appDelegate類改變它

AppDel.firstVariable =cell.textLabel.text; 
AppDel. secondVariable = cell.detailTextLabel.text; 
[myView addSubview:thirdView.view]; 

進程訪問在第三類值是 在viewDidLoad中{ MyAppnameDelegate AppDel =(MyAppnameAppDelegate *)[ [UIApplication sharedApplication]委託]; // MyAppnameDelegate是你appdelegete類,所以你的appDelegate類

nsstring *accessfirstVariable  =.AppDel.firstVariable 
nsstring *accesssecondVariable =AppDel. secondVariable 
} 

改變它,使用過的位置ü喜歡...乾杯

+0

@vijay ...謝謝兄弟....尋求幫助 – GauravBoss

+0

** welcome,親愛的 –