问题描述
我有两种看法.第一:FirstViewController第二:SecondViewController
i have got two view.First: FirstViewControllerSecond: SecondViewController
FirstViewController 是我的 UINavigationController 的根控制器,在 FirstViewController 中,我有UITableView.在UITableView中单击一个单元格时,该视图将导航到 SecondViewController .在 SecondViewController 里面,我有UILabel.我想将此UILabel的值分配给在导航栏"中单击后退"按钮 时在FirstViewController 上单击的单元格.我应该怎么做才能实现这一点?
FirstViewController is my UINavigationController's root controller and inside FirstViewController I ve got UITableView. When a cell is clicked in UITableView, the view is navigated to SecondViewController. Inside SecondViewController i have UILabel. I want to assign this UILabel's value to the cell which is clicked at FirstViewController when Back button is clicked in Navigation Bar. What am i supposed to do to implement this?
我可以通过创建以下内容将值从FirstViewController传递给SecondViewController:
I can pass value to SecondViewController from FirstViewController by creating:
SecondViewController * sv;sv.somestring = someotherotherstring;
SecondViewController *sv;sv.somestring = someanotherstring;
但是不能在SecondViewController上实现此功能,以将值传递给FirstViewController中的NSString.
but can not implement this at SecondViewController to pass the value to a NSString in FirstViewController.
你能帮我吗?
谢谢.AE
推荐答案
是的,有很多简单的方法可以解决这个问题.....
Ya , there is much a easy way to handle this.....
您可以采用全局变量
在您的 Delegate.h 文件中声明您的变量:
In your Delegate.h file declare your variable:
@interface Smoke_ApplicationAppDelegate : NSObject {
UIWindow *window;
UINavigationController *navigationController;
NSString *messageString; //This would be your String Variable
}
@property(nonatomic,retain)NSString *messageString;
其次是 Delegate.m 文件
@implementation Smoke_ApplicationAppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize messageString; // Synthesize it over here..
完成.现在,您可以在所有/任何所需的类中使用此字符串变量.
This is Done .Now you can use this String Variable in All/any class you want..
要使用此全局变量.
只需 导入您的代理文件即可使它成为obj ....
Just import you Delegate file make the obj of it....
import "DelegateFile.h"
@implementation About
DelegateFile *appDel;
现在在您的班上.m
-(void)viewDidLoad { [super viewDidLoad];
appDel=[[UIApplication sharedApplication]delegate];
}
现在,您可以通过此对象在班上的任何地方访问它:
Now you can access it anywhere in your class by this Object:
appDel.messageString
只要认真按照我的步骤操作,我相信这肯定会为您提供帮助.....
Just follow my Steps Carefully , I am sure this is definitely going to help you.....
过着轻松的生活,
这篇关于将参数从视图传递回另一个视图的UITableView的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!