Delegate method not being accessed - iphone

I am passing some information from one view to the other using delegates, However when I select a tableview cell I am passing the data to the delegate that will pas the information back to a view on the stack.. it makes it back to that view but doesn't actually go into the delegate method when the views change...
Here is where I set up my delegate.
subViewController.h
#import <UIKit/UIKit.h>
#protocol PassSubSearchData <NSObject>
#required
- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath;
#end
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
id <PassSubSearchData> delegate;
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
#property (strong) id delegate;
//This is how I use it
subViewController.m
#import "MainViewController.h"
#import "SubViewController.h"
#implementation VehicleSubResultViewController
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
#synthesize delegate;
//...
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Access selected cells content (cell.textLabel.text)
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Predicates restrict the values that will be returned from the query
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"%K like %#",#"SUB",cell.textLabel.text];
filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];
[[self delegate] setModSearchFields:tempModArray modIndexPath:tempModIndexPath setSubMod:filterArray subModIndexPath:indexPath];
//This pops to the VehicleSearchViewController view
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
Then in the main view
MainViewController.h
#import "SubViewController.h"
#interface VehicleSearchViewController : UITableViewController <PassSubSearchData> {
//...
MainViewController.m // However this part of the code is never accessed
- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath
{
modObjectString = [[modArray valueForKey:#"MOD"] objectAtIndex:0];
modIndexPath = modIndexPath; // Sets the selected IndexPath from the subview
subModObjectString = [[modelArray valueForKey:#"SUBMODEL"] objectAtIndex:0];
subModIndexPath = subModResultIndexPath; // Sets the selected IndexPath from the subview
NSLog(#"%#", modObjectString);
NSLog(#"%#", modIndexPath);
NSLog(#"%#", subModObjectString);
NSLog(#"%#", subModIndexPath);
[self.tableView reloadData];
}
So thats it, I'm just not sure what I'm missing if anyone knows any help would be appreciated.

Most likely the delegate never got set, so it is nil and nothing happens.

Related

How do I add a UITableView to a parent that contains other objects?

This is essentially the layout I want:
The UITableView at the bottom should accomodate comments to a specific post, adding a row for each comment.
The UITableView at the bottom is wired to commentTable; all other elements are wired accordingly as well.
When I build and run, no errors, but I only see one empty table cell below the post.
I know there's something missing in loading/passing data to my table, but I wonder if someone can give me a direction on how to make this work.
DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController {
IBOutlet UIImageView *postThumbView;
IBOutlet UILabel *postTextLabel;
IBOutlet UIImageView *postAuthorPictureView;
IBOutlet UILabel *postAuthorNameLabel;
IBOutlet UILabel *postTimestampLabel;
IBOutlet UIScrollView *scroller;
IBOutlet UITableView *commentTable;
}
#property (strong, nonatomic) id detailItem;
#end
DetailViewController.m
#import "DetailViewController.h"
#interface DetailViewController ()
- (void)configureView;
#end
#implementation DetailViewController;
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
- (void)configureView
{
if (self.detailItem) {
NSDictionary *post = self.detailItem;
NSString *postText = [post objectForKey:#"post_text"];
...
postTextLabel.text = postText;
...
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSDictionary *post = self.detailItem;
NSDictionary *commentThread = [post objectForKey:#"comment"];
return commentThread.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"commentCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *post = self.detailItem;
NSDictionary *commentThread = [post objectForKey:#"comment"];
NSString *commentText = [commentThread objectForKey:#"comment_text"];
NSString *commentAuthorName = [commentThread objectForKey:#"comment_author_name"];
cell.textLabel.text = commentText;
cell.detailTextLabel.text = [NSString stringWithFormat:#"by %#", commentAuthorName];
return cell;
}
#end
It may be that the table view delegate method's you've written aren't being called. The first thing you should do is set breakpoints inside these methods, run your app, and see if they are being called.
If they're not being called, you may have failed to set your delegate. In this case, it appears that you are not using a discrete UITableViewController, rather you are attempting to have your DetailViewController supply the necessary information for the tableView to work as expected.
First, you need to conform your DetailViewController to the UITableViewDelegate protocol:
#interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
Second, you need to actually set the delegate #property of your UITableView. You can do this in interface builder (select the tableview, right click, drag it's delegate property to connect to your DetailViewController, which may or may not be File's Owner). If you'd rather do it in code, you just need to call (early in the VC's life, in viewDidLoad, for example):
self.tableView.delegate = self;
self.tableView.datasource = self;
So... assuming your delegate is all wired up properly, you should then go back and test those breakpoints to see if the table view's methods are being called. If they are being called, the next step would be to evaluate the variables when the breakpoints are called, examine for example if the numbers being return in numberOfRowsInSection and the values in cellForRowAtIndexPath match what you anticipate.
You need to declare your view controller as the delegate and data source for the table view
change this line in your .h file
#interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
Then in your viewDidLoad
commentTable.dataSource = self;
commentTableView.delegate = self;
[commentTableView reloadData];
[self configureView];
You can also look in the story board, and connect the outlets n the same way you connected commentTable to your UITableView, but by dragging in the opposite direction and selecting data source and delegate

How to pass/send the number of selected row in UITableViewController to another class?

Dudes, i'm having some trouble here in XCODE4.5 and I hope you can help me!
How can I pass or send the integer value of the selected row in UITableViewController to another ViewController, using the method didSelectRowAtIndexPath?
Here is my code :
SecondViewController.h
{
NSInteger myInteger;
}
#property(nonatomic) NSInteger myInteger;
SecondViewControl.m
-(void)viewDidLoad {
NSLog(#" the number is = %d",myInteger); //this is not working, I always get "the number is = 0 "
}
FirstViewController.h
#import "SecondViewController"
//...
FirstViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath) {
NSIndexPath *path = indexPath;
NSInteger theInteger = path.row;
NSLog(#"selected row = %d", theInteger); //code OK
//THE PROBLEM STARTS HERE!!!!!!!!!!!!!!!!!!
SecondViewController *second = [[SecondViewController alloc]init];
[second setMyInteger:theInteger];
// i'm trying to use "second.myInteger = theInteger;" , but it's also not working
}
}
Thank you guys!
Your myInteger iVar is unused b/c of how the compiler generates iVars and synthesizes getters/setters automatically for properties.
The compiler helps you when you declare properties so you don't need to declare your own iVars or use #synthesize unless you want behavior other than the default.
The line #property(nonatomic) NSInteger myInteger; causes the compiler to generate the equivalent of the following in your implementation.
#synthesize myInteger = _myInteger;
Therefore, the iVar being modified by the default setter is _myInteger.
You can do one of the following in SecondViewController. I prefer solution #1 b/c it is cleaner, less code and takes advantage of automatic compiler behavior.
In SecondViewController.h remove the myInteger iVar and in SecondViewController.m change any references to the iVar to either _myInteger or self.myInteger
or
In SecondViewController.m, explicitly synthesize the property to use your iVar by adding #synthesize myInteger;
EDIT: ADDED SPECIFIC EXAMPLE
// SecondViewController.h
#interface SecondViewContoller : UIViewController
#property(nonatomic) NSInteger myInteger;
#end
// SecondViewControl.m
-(void)viewDidLoad {
NSLog(#" the number is = %d", self.myInteger);
}
// FirstViewController.h
#import "SecondViewController"
//...
// FirstViewController.m
//
// rest of implementation
//
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath) {
NSIndexPath *path = indexPath;
NSInteger theInteger = path.row;
NSLog(#"selected row = %d", theInteger);
SecondViewController *second = [[SecondViewController alloc] init];
second.myInteger = theInteger;
// you need to present second somehow, viewDidLoad won't be called until then
// example if using a navigationController
[self.navigationController pushViewController:second animated:YES];
}
}
Passing parameters onto the next one should be done in the prepareForSegue:sender: method assuming you're using Storyboards in Xcode 4.5.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:#"YOUR_SEGUE_NAME_HERE"])
{
SecondViewController *second = (SecondViewController *)segue.destinationViewController;
second.selectedIndex = selectedIndex;
}
}
Then in your didSelectRowAtIndexPath: method you can perform the segue:
[self performSegueWithIdentifier:#"YOUR_SEGUE_NAME_HERE"];
And it should pass the parameter to your second view again assuming you have a property in the header file of your SecondViewController like such:
#property (nonatomic, assign) int *selectedIndex;
EDIT:
In context with what you're trying to do you can easily make a private property in your FirstViewController at the top and store your selectedIndex from your didSelectRowAtIndexPath: there and pass it through in the prepareForSegue:
#interface FirstViewController() {
int selectedIndex;
}
And
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndex = indexPath.row
}
Hi i think you are missing to synthesize the myInteger Veriable modify your secondviewcontroller.m file
SecondViewControl.m
#synthesize myInteger;
-(void)viewDidLoad {
NSLog(#" the number is = %d",myInteger);
}
Hopefully this will help you :)

How to pass value from second class of UITextField to first view class on UITableViewCell in iPhone

Hi I tried another code for passing data but it is not working. How to pass UITextField value on firstview on UITableViewCell on row? Please someone help me on delegate protocol
//
// first.h
// TextviewExample
//
// Created by pradeep.yadav on 12/5/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "second.h"
#import "TextviewExampleAppDelegate.h"
//#class second;
#interface first : UITableViewController <secondDelegate>{
//TextviewExampleAppDelegate*app;
//TextviewExampleAppDelegate *check;
second *secondview;
NSString *secondFavoriteColorString;
//second *value;
}
#property (nonatomic, retain) second *secondview;
#property (copy) NSString *secondFavoriteColorString;
#end
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text=#"message";
cell.detailTextLabel.text=secondFavoriteColorString;
NSLog(#"this second check:%#",secondFavoriteColorString);
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
second *viewTwo = [[second alloc] initWithNibName:#"second" bundle:[NSBundle mainBundle]];
self.secondview = viewTwo;
[viewTwo release];
[self.navigationController pushViewController:self.secondview animated:YES];
}
-(void)setsecond:(NSString*)secondtextview
{
secondFavoriteColorString = secondtextview;
NSLog(#"this second check:%#",secondFavoriteColorString);
}
this second class
//
// second.h
// TextviewExample
//
// Created by pradeep.yadav on 12/5/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#protocol secondDelegate<NSObject>
#required
-(void)setsecond:(NSString*)secondtextview ;//forIndexPath:(NSIndexPath*)indexPath;
#end
#interface second : UIViewController {
IBOutlet UITextField *secondtextfield;
NSString *favoriteColorString;
id <secondDelegate> delegate;
}
#property (nonatomic,retain)UITextField *secondtextfield;
//#property (nonatomic,assign)id<secondDelegate>delegate;
#property (retain) id delegate;
#property (nonatomic,copy)NSString *favoriteColorString;
#end
#import "second.h"
#implementation second
#synthesize delegate,secondtextfield,favoriteColorString;
- (void) viewWillDisappear:(BOOL) animated
{
[[self delegate] setsecond:secondtextfield.text];
favoriteColorString=secondtextfield.text;
NSLog(#"thuis check:%#",favoriteColorString);
}
- (BOOL) textFieldShouldReturn: (UITextField *) theTextField
{
[theTextField resignFirstResponder];
return YES;
}
I think the trouble is that you have declared the delegate in the second view, and you are trying to call it from the first view. By the time you have returned to the first view, it's very likely that the second view has been cleaned up.
What you want to do is declare the delegate methods in the first view controller, and when you create the second view controller, you set the first view controller to be the delegate of the second view controller.
I created an example project a while ago. It doesn't deal with a table view, but it demonstrates passing a string back from a second view controller to the first view controller.
Here is a link to a tutorial how to share data between viewController:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/54859-sharing-data-between-view-controllers-other-objects.html
It should help you out to solve your problem.
From TextField in View1 to Cell in View2
Take a String in Second View.
Property, synthesize it,
While moving from first view to second view Assign the value of UITextField to the synthesized string right after allocating and before pushing.
In second view display the text in synthesized string on the cell.
From TextField in View2 to Cell in View1
Take a String in First View.
Property, synthesize it,
Take a object of FirstView in secondView and property and synthesize it
While moving from first view to second view Assign the value of objSecondView.objFirstView=self; after allocating and before pushing.
Now in second view assign the value of text to firstViews synthesized string.
And in viewWillAppear of firstView assign the value of its string to the cell
E.g. Your method in the above example must look loke the one below
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
second *viewTwo = [[second alloc] initWithNibName:#"second" bundle:[NSBundle mainBundle]];
viewTwo.objViewOne = self;
[self.navigationController pushViewController:viewTwo animated:YES];
[viewTwo release];
}
Thats it.. Comment if still any problem faced.

Delegate not working properly

I am trying to pass some information between a subview and a parentview on the navigation stack using delegates.
However for some reason when the I execute the delegate from the subview then pop the subview from the navigational controller it never enters the delegate method that is set up in the parent view.. I have tried NSLogs & Breakpoints the thread is defiantly not making it to this delegate method in the main view so I was hoping you could help me out.
First Of all I will show you how I have set up my delegate, where I call it in my subview and then where I set it up in the mainview hopefully you guys will be able to see something I have not so far.
Subview.h // I have left out things not related to the delegate
#import <UIKit/UIKit.h>
//Delegate - Protocol stuff for passing data from this view to the parent view
#protocol PassSearchData <NSObject>
#required
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath;
#end
#interface SecondViewController : UITableViewController <UITableViewDataSource> {
//Delegate (Used to pass information back to parent view)
id <PassSearchData> delegate;
}
//Delegate (Used to pass information back to parent view)
#property (strong) id delegate;
#end
SecondView.m
#import "SecondViewController.h"
#import "FirstViewController.h"
#implementation SecondViewController
//..
//Delegate (Used to pass information back to parent view)
#synthesize delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Access selected cells content (cell.textLabel.text)
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Parent view logic (sends info back to the correct cell in parent view)
if (parentViewSelectedIndexPath.section == 0)
{
if (parentViewSelectedIndexPath.row == 0)
{
//Predicates restrict the values that will be returned from the query
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"%K like %#",#"MANUFACTURER",cell.textLabel.text];
filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];
[[self delegate]setManufactureSearchFields:filterArray withIndexPath:indexPath];
// NSLog(#"Filtered Array = %#", filterArray);
}
}
[self.navigationController popViewControllerAnimated:YES]; //pops current view from the navigatoin stack
}//...
Then this is how I set it up inside the FirstViewController
FirstViewController.h
#import <UIKit/UIKit.h>
#import "VehicleResultViewController.h" //With this included I can now use the PassSearchData delegates of this view for passing data
#interface VehicleSearchViewController : UITableViewController <PassSearchData> {
//..
FirstViewController.m
#import "VehicleSearchViewController.h"
#import "VehicleResultViewController.h" //Subview
//..
#pragma mark - Received data from Sub view delegates
//These are the delegate method for passing data from the child to the parent view (parent being this view, with the delegate being declared in the subview)
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [[arrayValues valueForKey:#"MANUFACTURER"] objectAtIndex:0];
manufactureIdString = [[arrayValues valueForKey:#"MANUFACTURERID"] objectAtIndex:0]; //Restricts Models dataset
manufactureResultIndexPath = myIndexPath;
}
If anyone knows what I'm missing/doing wrong any help would be really really heapful
any questions let me know.
Solution
In the firstviewcontroller when I go to load the secondviewcontroller inside
tableView:didSelectRowAtIndexPath: I forgot to set the secondviewcontrollers delegate before I pushed the view to the navigational stack.. so the missing code was this.
FirstView.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the subview ready for use
VehicleResultViewController *vehicleResultViewController = [[VehicleResultViewController alloc] initWithNibName:#"VehicleResultViewController" bundle:nil];
//Pass the selected object to the new view controller.
[self.navigationController pushViewController:vehicleResultViewController animated:YES];
[vehicleResultViewController setDelegate:self];
//etc
thanks guys.
Ok, first, your delegate should be a weak reference to avoid retain cycles. But I suspect maybe the delegate isn't getting set. Can you show the code where SecondViewController is instantiated and the delegate is set? Can you set a breakpoint at the delegate call and verify that it is not nil?
I think you are not setting Delegate.
After Creation Instanace(object)of SecondViewController ,you have to set Delegate.
ie
SecondViewController *secondObj=[[SecondViewController alloc]initWithNibName:#"SecondViewController"> bundle:nil];
[secondObj setDelegate:self];

how to send data backword from second class to first class in iphone

i am try to exchange the one cell to the value of other cell but my value is not transfer proper bec my value is passing second class to first class but not string value is passing array reference why what is the mistake in my code can u help me
for this i create delegate method
this is my originstart.h file
import
#import "RegexKitLiteDemoAppDelegate.h"
#class airport;
#protocol OriginstartDelegate <NSObject>
#required
- (void)Originstart:(NSString *)Origin forIndexPath:(NSIndexPath *)indexPath;
#end
#interface Originstart : UITableViewController {
RegexKitLiteDemoAppDelegate *app;
airport *selectedAirport;
}
#property(nonatomic,retain)NSString*name;
#property(nonatomic,retain)airport *selectedAirport;
#property (nonatomic, copy) NSIndexPath *indexPathToChange;
#property (nonatomic, assign) id<OriginstartDelegate> delegate;
#end
this is my orginestart.m file
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return app.lstAirports.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
airport* a=(airport*)[app.lstAirports objectAtIndex:indexPath.row];
NSLog(#"str:%#",a);
cell.textLabel.text =a.Name;
cell.detailTextLabel.text=a.Code;
// Configure the cell...
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *newStation = [[app.lstAirports objectAtIndex:indexPath.row]description];
[delegate Originstart:newStation forIndexPath:self.indexPathToChange];
[self.navigationController popViewControllerAnimated:YES];
}
this is my Tfirst.m file
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"accessory selected");
if ([indexPath section] == 0)
{
// load the appropriate view for the accessory selected
if ([indexPath row] == 0)
{
Originstart *viewtwo = [[Originstart alloc] initWithStyle:UITableViewStyleGrouped];
viewtwo.indexPathToChange = indexPath;
viewtwo.delegate = self;
[self.navigationController pushViewController:viewtwo animated:YES];
[viewtwo release];
}
else{
NSLog(#"accessory right");
}
}
}
#pragma mark - Delegate protocol method
- (void)Originstart:(NSString *)Origin forIndexPath:(NSIndexPath *)indexPath {
[datasource replaceObjectAtIndex:indexPath.row withObject:Origin];
[self.tableView reloadData];
}
this is my airport.h file where i create two string variable and one array for take value and display for in originstart classwith name and code i writen this in here in class
originstart.m airport* a=(airport*)[app.lstAirports objectAtIndex:indexPath.row];
NSLog(#"str:%#",a);
cell.textLabel.text =a.Name;
cell.detailTextLabel.text=a.Code;
and final this class arport class
//
// airport.h
// RegexKitLiteDemo
//
// Created by pradeep.yadav on 9/13/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#interface airport : NSObject {
NSString *Code;
NSString *Name;
NSArray *DestinationAirports;
}
#property(nonatomic,retain)NSString *Code;
#property(nonatomic,retain)NSString *Name;
#property(nonatomic,retain)NSArray *DestinationAirports;
#end
To achieve what u want , just try these steps:
1.First, create a property of first class in the second class.
2.In the first class create those variables or objects as properties to which u want to pass the data from the second class.
3.(Hope u are using navigation controller based app ) While pushing from the first to second view controller u create a instance of the second class and pass it pushViewController method. Add the following line of code along with it.....
secondViewObj.firstView=self;
where secondViewObj is the instance of the secondViewController class and firstView is the property declared in that second class.
4.Now in the second class when u want to pass the data to first class just add the following line of code:
firstView.dataMember1=value;
where dataMember1 is the variable or object which was created as a property as mentioned in the 2nd point. Hope this helps.
In the FirstViewController class where u push to SecondviewController have the following piece of code:
SecondViewController *svc = [SecondViewController alloc]init];
svc.vc = self;
[self.navigationController pushViewController:svc animated:YES];
and also have a property declared for the data u want to pass to the firstView Controller.
In this case it s going to be a integer variable.
#property (nonatomic) int selectedValue and also synthesize it.
Now in the secondViewController , declare a property for the firstViewController like this
#property (nonatomic, retain) FirstViewController *vc; and synthesize it.
Where u want to pass the data to the FirstViewController have the following code,
vc.selectedValue = 1;
Now after popping back to the firstViewController , if u chk the value of the selectedValue variable u will find the value has been passed from second to first.
Hope this helps..
The simplest apprroach is to set an object in FirstViewController here is the way
SecondViewController
FirstViewController *instanceOfFirstView;
#property (nonatomic, retain) FirstViewController *instanceOfFirstView;
#synthesize instanceOfFirstView;
[instanceOfFirstView setValueNeedTobeBroughtFromSecondView:#"VAlue set"]
FirstViewController
NSString *valueNeedTobeBroughtFromSecondView;
#property (nonatomic, retain) NSString *valueNeedTobeBroughtFromSecondView;
#synthesize valueNeedTobeBroughtFromSecondView;
SecondViewController *aSecondViewController=[[SecondViewController alloc] init];
[aSecondViewController setInstanceOfFirstView: self];