使用导航栏时如何将值从view2返回到view1 [英] How return a value from view2 to view1 when using navigation bar

查看:124
本文介绍了使用导航栏时如何将值从view2返回到view1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发新手。使用导航栏时,如何将字符串值从view2传送到view1。通过使用pushviewcontroller将字符串值从view1传递到view2到view3到....我没有问题但是当我使用导航栏的Back按钮回到以前的视图时,我无法保存字符串值。
我需要你的帮助来解决这个问题。

I am New to the iPhone Development. How can i carry a string value from view2 to view1 when using navigation bar. I have no problem in carrying string values from view1 to view2 to view3 to....by using pushviewcontroller But when i come back to previous views using Back button of navigation bar, I cannot able to hold string values. I need your help in solving this issue.

提前谢谢

推荐答案

如果将当前类的引用传递给下一个类并使用此引用更改值,则可以轻松完成此事。

This thing can be done easily if the pass the reference of the current class to the next class and change the values by using this reference.

Like :
要推送的类。

Like: The class that is to be pushed.

@interface B:UIViewController{
   id delegate;
}
@property (nonatomic,retain) id delegate;
@end

@implementation B
@synthesize delegate;

-(void)methodA{
  [delegate setNewString2:@"Madhup"];
}

@end

您所在的班级推B:

@interface A:UIViewController{
   NSString *newString;
}
@property (nonatomic,retain)  NSString *newString;
@end


 @implementation A
 @synthesize newString
- (void)method2{
     B *newBObject = .......;
     [newBObject setDelegate:self];
     [self.navigationController pushViewCo.......];
  }
 @end

希望这有帮助。

这篇关于使用导航栏时如何将值从view2返回到view1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆