2011-11-04 75 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,亲爱的 –