Home >Web Front-end >HTML Tutorial >Several page jumps and value passing (notification value passing)_html/css_WEB-ITnose

Several page jumps and value passing (notification value passing)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:50:441143browse

A→B→C→D→A

A is not the root directory, but it needs to jump back to D without alloc. In this case, we can use the following Method

[self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex: ([self.navigationController.viewControllers count] -4)] animated:YES];


And D wants to pass a value to A, then notification is very useful

Notification passing value (one sender, a bunch of receivers, no proxy protocol is required, directly through the system’s notification center Work notificationCenter)

On the value transfer page

First get a system notification center

NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

NSNotification * notify = [NSNotification notificationWithName:@"regisonName" object:[NSString stringWithFormat:@"%@",[self.dataArray[indexPath.row] objectForKey:@"name"]]];

// The first parameter is the name of the notification, which is the label. Give it a name in case you use this name to find the object. The second parameter is the value you want to pass and the value you want to receive. This value must be an object
[center postNotification:notify];

On the receiving page

//NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

[[NSNotificationCenter defaultCenter] addObserver:self
                                                                                                          :@"regisonName"

     The second parameter (method name, the work to be done) The third parameter (the name of the work, must be consistent with the sender) The fourth parameter (system, don’t worry about it for now)

- (void)setRegionTitle:(NSNotification *)notify{

NSString * object = [notify object];

[_regionButton setTitle:object forState:UIControlStateNormal];

[_regionButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn