I am new to iOS and I am not able to pass data from one controller to another. I am not able to access the variable in the second view controller
this is my method for passing I have created a delegate in .h file of receiving view controller
.h file of first view controller (sending)
#interface OtpViewController : UIViewController
#property (nonatomic,strong) NSString *str;
#property (strong,nonatomic) NSString *tmp;
#property(weak,nonatomic) NSString *requestReply ;
.m file of first view controller(sending)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{
VerifyViewController *loadCtr = (VerifyViewController *)segue.destinationViewController;
loadCtr.delegate = self;
loadCtr.tmpStr = self.tmp;
NSLog(#"--%#",self.tmp);
[loadCtr setotp:self.tmpdict withMobile:_mobiletf.text];
//NSLog(#"otp:%#",[tmpdict valueForKey:#"otp"]);
NSLog(#"mobile:%#",_mobiletf.text);
}
.m file of second view controller(receiving)
-(void)setotp:(NSDictionary *)dic withMobile:(NSString *)str{
self.stri=[tmpdict valueforkey:#"otp"];
self.stri1=_mobiletf.text;
OtpViewController.[tmpdict valueforkey:#"otp"]=self.stri;
NSLog(#"%#----%#",self.stri,self.stri1);
}
.h file of second view controller(receiving)
#protocol VerifyViewControllerDelegate <NSObject>
#end
#interface VerifyViewController : UIViewController
#property (nonatomic,strong) NSString *otpStr;
#property(nonatomic,strong) NSString *mobileStr;
#end
actually I am trying to get otp from server and I have extracted the otp in the first view controller and now I have to pass otp and the mobile number from the text field to second view controller for verification of the otp please help!!
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
// NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object
NSLog(#"requestReply: %#", jsonDict);
self.tmp=[jsonDict valueForKey:#"otp"] ;
self.str=self.tmp;
NSLog(#"tmp storage inside block:%#",self.tmp);
}] resume];
[ self performSegueWithIdentifier:#"b1" sender:self];
NSLog(#" storage:%#",self.str);
NSLog(#"tmp storage:%#",self.tmp);
}
at log whatever is printed which is out of resume gives me null
this is my log data
2017-06-01 12:26:45.803 MenuBar[2652:124758] 9047038606
2017-06-01 12:26:45.809 MenuBar[2652:124758] storage:(null)
2017-06-01 12:26:45.810 MenuBar[2652:124758] tmp storage:(null)
2017-06-01 12:26:48.422 MenuBar[2652:124804] requestReply: {
otp = 325106;
success = 1;
}
2017-06-01 12:26:48.422 MenuBar[2652:124804] tmp storage inside block:325106
Use Below code:
#interface VerifyViewController : UIViewController
#property (nonatomic,strong) NSString *otpStr;
#property(nonatomic,strong) NSString *mobileStr;
Then pass values:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender
{
VerifyViewController *loadCtr = (VerifyViewController *)segue.destinationViewController;
loadCtr.otpStr = [tmpdict valueForKey:#"otp"];
loadCtr.mobileStr = _mobiletf.text;
}
You can access these 2 values in ViewDidLoad method of VerifyViewController.
self.otpStr and self. mobileStr
(As of Xcode Version 9.4.1 (9F2000) - iOS 11.4 - Objective C)
Most will need to call several storyboard segue calls from a single UIViewController. Here is how to handle the different segue string identifiers within the preparForSegue delegate call.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([segue.identifier isEqualToString: #“CallerViewController_ToMusicPlayerViewController_Segue"])
{
MusicPlayerViewController * targetVC = (MusicPlayerViewController *)segue.destinationViewController;
targetVC.listName = #“Music Hits”;
}
if ([segue.identifier isEqualToString: #“CallerViewController_ToMusicListViewController_Segue"])
{
MusicListViewController * targetVC = (MusicListViewController *)segue.destinationViewController;
// if you need to manage a protocol delegate with caller VC
targetVC.savefolderChoiceDelegate = self;
}
}
The actual call to invoke the segue looks like:
-(void)buttonAction:(id)sender{
[self performSegueWithIdentifier:#“CallerViewController_ToMusicPlayerViewController_Segue" sender:sender];
}
Here is an example of Interface Builder Segue. the identifier is different, but imagine #“CallerViewController_ToMusicPlayerViewController_Segue" is actually #"ProtData_Add_Segue" in this image.
Related
I am creating a iOS static library in which user will pass the name of the Viewontroller and some parameters inside the push and I am getting these details in didReceiveRemoteNotification and from here I got a string suppose NSString *vcName = #"ViewController2" and parameter suppose NSString *param1= #"UserName" NSString *param2= #"email" now I want to pass these parameters to the viewController Which name's string is received from push. But I don't want to write #import ViewController2.
I am able to redirect to ViewController2 without importing it but don't know how to pass these parameters to ViewController2
I can redirect to the viewController from the following code.
NSString *vcName = #"ViewController2";
NSString *param1= #"UserName";
NSString *param2= #"user_email";
UIStoryboard * storyboard = [[[UIApplication sharedApplication] keyWindow] rootViewController].storyboard;
UIViewController *vcToOpen = [storyboard instantiateViewControllerWithIdentifier:vcName]];
vcToOpen.modalPresentationStyle =UIModalPresentationFullScreen;
[[[[UIApplication sharedApplication]keyWindow] rootViewController] presentViewController:vcToOpen animated:YES completion:nil];
Now I want to get these two parameter's value in ViewController2. Can anybody help me how to do it. without writing #import ViewController2 because app can has many ViewControllers and vcName can be any of them.
AppDelegate.h
-(NSString *)getEmail;
-(NSString *)getName;
-(void)setEmail:(NSString *)email Name:(NSString *)name;
+(AppDelegate *)sharedAppDelegate;
AppDelegate.m
#interface AppDelegate ()
{
NSString *strEmail, *strName;
}
-(NSString *)getEmail
{
return strEmail;
}
-(NSString *)getName
{
return strName;
}
-(void)setEmail:(NSString *)email Name:(NSString *)name
{
strEmail = email;
strName = name;
}
+(AppDelegate *)sharedAppDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
ViewController1.m
#import "AppDelegate.h"
-(void)gotoViewController2
{
[[AppDelegate sharedAppDelegate] setEmail:#"email#gmail.com" Name:#"name1234"];
[self performSegueWithIdentifier:#"segueToViewController2" sender:nil];
}
ViewController2.m
#import "AppDelegate.h"
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *name = [[AppDelegate sharedAppDelegate]getName];
NSString *email = [[AppDelegate sharedAppDelegate]getEmail];
NSLog(#"name = %# and email = %#",name, email); //name = name1234 and email = email#gmail.com
}
Storing values in your app delegate is just messy.
Each one of your UIViewControllers that could be launched from a push notification could conform to a custom 'launch' protocol.
Each UIViewController e.g. 'UIViewController2' would conform to this protocol.
You could write the protocol like this:
#protocol LaunchProtocol <NSObject>
- (void) launchParams:(NSDictionary *)params;
#end
Each UIViewController could conform to this protocol, like so:
#interface ViewController2 : UIViewController <LaunchProtocol>
#end
#implementation ViewController2
- (void) launchParams:(NSDictionary *)params {
}
#end
Your app delegate only needs to know about the protocol, it doesn't care about your UIViewControllers.
When you get a push notification you check if the view controller conforms to the launch protocol.
...
vcToOpen.modalPresentationStyle =UIModalPresentationFullScreen;
if ([vcToOpen conformsToProtocol:#protocol(LaunchProtocol)]) {
UIViewController <LaunchProtocol> *launchController = (UIViewController <LaunchProtocol> *) vcToOpen;
NSDictionary* params = #{ /* create your param dict */ };
[launchController launchParams:params];
}
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:vcToOpen animated:YES completion:nil];
...
You would include the information from the push notification in the 'params' dict, and the UIViewController would extract what information it needs from it in launchParams:
- (void) launchParams:(NSDictionary *)params {
NSLog(#"Username: %#", params[#"username"]);
}
Actually you can use Singleton design pattern to achieve this. Create one shared instance class to store the values.
+ (instancetype)sharedInstance
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
create properties inside the manager class which needs to be saved, then access the values from the manager class.
I decided to go with an embedded API call within a view controller, and I'm having trouble with the data reaching out before the API returns with the information.
How do I wait for the data to be returned before the view controller displays all the values as nulls?
Thanks for any help.
#import "BDChangeApproveController.h"
#import "BDItemChangeDetailAPI.h"
#interface BDChangeApproveController () <NSURLSessionDelegate>
#property (nonatomic, strong) NSURLSession *session;
#property (nonatomic, copy) NSArray *APIItem;
#end
#implementation BDChangeApproveController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)fetchFeedAPIChangeDetail
{
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
_session = [NSURLSession sessionWithConfiguration:config
delegate:nil
delegateQueue:nil];
NSString *requestString = #"http://URL.com";
NSURL *url = [NSURL URLWithString:requestString];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSURLSessionDataTask *dataTask =
[self.session dataTaskWithRequest:req
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error){
NSDictionary *jsonObject1 = [NSJSONSerialization JSONObjectWithData:data
options:0
error:nil];
//NSLog(#"%#", jsonObject1);
self.APIItem = jsonObject1[#"CoDetail"];
NSLog(#"%#", self.APIItem);
}];
[dataTask resume];
}
//API authentication
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
NSURLCredential *cred =
[NSURLCredential credentialWithUser:#"demouser"
password:#"secret"
persistence:NSURLCredentialPersistenceForSession];
completionHandler(NSURLSessionAuthChallengeUseCredential, cred);
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self fetchFeedAPIChangeDetail];
self.title = #"Action";
self.coNumberLabel.text = self.itemAPI.changeOrder;
//self.recipeImageView.image = [UIImage imageNamed:self.recipe.image];
NSLog(#"testtttt");
NSMutableString *coDetailsText = [NSMutableString string];
coDetailsText =
[[NSMutableString alloc] initWithFormat:#"Review Change Order details bellow\n====================\n%# \n================== \nPlanned Start %#\n==================\nSubcategory: %#\n==================\nService: %#\n==================\nAssociated CIs: %#\n==================\nEnvironment CI: %#\n==================\nApproval Group: %#\n==================\nInitiator : %#\n==================\nCoordinator : %#\n==================\nRisk Level : %#\n==================\nPerforming Group : %#\n==================\nImplementation Plan : %#\n==================\nStatus : %#\n==================\nRecovery Plan : %#\n==================\n",
/*
self.item.title,
self.item.changeOrder,
self.item.subcategory,
self.item.assignmentGroup,
self.item.changeOrder,
self.item.subcategory,
self.item.assignmentGroup,
self.item.approverEid,
self.item.approverEid,
self.item.subcategory,
self.item.assignmentGroup,
self.item.title,
self.item.title,
self.item.title
*/
self.itemAPI.title,
self.itemAPI.plannedStart,
self.itemAPI.subcategory,
self.itemAPI.service,
self.itemAPI.associatedCi,
self.itemAPI.environment,
self.itemAPI.assignmentGroup,
self.itemAPI.initiator,
self.itemAPI.coordinator,
self.itemAPI.riskLevel,
self.itemAPI.performingGroup,
self.itemAPI.implementationPlan,
self.itemAPI.status,
self.itemAPI.recoveryScope
// self.item.valueInDollars,
// self.item.dateCreated,
// self.item.subcategory,
// self.item.service,
// self.item.associatedCIs,
// self.item.environment,
// self.item.approvalGroup,
// self.item.initiator,
// self.item.coordinator,
// self.item.riskLevel,
// self.item.performingGroup,
// self.item.implementationPlan,
// self.item.validationPlan,
//self.item.recoveryScope
];
self.coDetailsTextView.text = coDetailsText;
NSLog(#"overrrr");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
// Adding File
#import <Foundation/Foundation.h>
#import "BDItemChangeDetailAPI.h"
#interface BDChangeApproveController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *coNumberLabel;
#property (weak, nonatomic) IBOutlet UITextView *coDetailsTextView;
#property (nonatomic, strong) BDItemChangeDetailAPI *itemAPI;
#end
Looks like you're doing something asynchronously and expecting it to act synchronously.
Look at the below piece of code you're using in viewDidLoad:
[self fetchFeedAPIChangeDetail]; // this takes some time to complete
self.title = #"Action"; // this happens immediately after the above starts, not ends
self.coNumberLabel.text = self.itemAPI.changeOrder; // so does this, so at this point itemAPI is probably nil
fetchFeedAPICheckDetail is an asynchronous process, so it might take a few seconds to complete, whereas setting the title and coNumberLabel happens immediately after, so you don't yet have the itemAPI information from the URL Session. Your code doesn't wait for fetchFeedAPIChangeDetail to be done with the request before continuing onto the next line.
Declare a function
-(void)refreshTextView
{
// set your text view text with the api result here
self.coNumberLabel.text = self.itemAPI.changeOrder;
}
Call this method in at the end of your request block after NSLog(#"%#", self.APIItem);
Like this
[self performSelectorOnMainThread:#selector(refreshTextView) withObject:nil waitUntilDone:NO];
When you will call this method in the block it will be called and will update the textview text with the api results. The block is asynchronous and so when you update your textview later it doesn't gets updated because the block has not yet completed its function and the array is still nil but calling this method in the block would assure that the result gets assigned and updated in the textview.
UPDATE
and you do have a typo here
#property (nonatomic, copy) NSArray *APIItem;
you are naming it with the class name thats a conflict.
Name it something else like #property (nonatomic, copy) NSArray *apiItem; Actually u have a class name APIItem declared because of which a conflict occurs and that is the very reason it is marked blue in xcode. look all class names are marked blue in your code. Like NSArray , NSURLSession etc –
I have an NSObject class that contains 3 methods:
-(void)RequestForData
{
#pragma Mark - ASIHTTPRequest
NSURL *url=[NSURL URLWithString:#"http://srv2.vitaminas.it/pdv"];
ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startSynchronous];
}
pragma Mark - HTTP Delegate
- (NSData*)requestFinished:(ASIHTTPRequest *)request
{
NSData *responseData = [request responseData];
return responseData;
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(#"%#",error);
}
I have one view controller class, from viewDidLoad method of viewcontroller class call -RequestForData method of NSObject class,
WebServiceMethods *web=[[WebServiceMethods alloc]init];
[web RequestForData];
arr_JsonData=[NSJSONSerialization JSONObjectWithData:web options:NSUTF8StringEncoding error:Nil];
NSLog(#"%#",arr_JsonData);
[self.tableView reloadData];
But I want to use NSData that are returned from NSObject class (i.e return responsedata; ) into view controller class.
I want that NSData into arr_JsonData ( NSMutuableArray )
What can I do ?
Make responseData as class level variable. Do not create local instance of it in requestFinished method.
Your problem is callbacks. You should put your viewController as a delegate of WebServiceMethods ( or using blocks is better) to be informed when the request has finished and the populate your arr_JsonData
#protocol WebServiceMethodsDelegate
- (void)webServiceMethodsDidFinishWithSucess:(NSString *)response; // give this méthode an appropriate name.
- (void)webServiceMethodsDidFailWithError:(NSError *)error;
#end
#interface WebServiceMethods : NSObject
#property (nonatomic,weak) id <WebServiceMethodsDelegate> delegate;
#end
#implemntation WebServiceMethods : NSObject
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
[self.delegate webServiceMethodsDidFinishWithSucess:responseString];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
[self.delegate webServiceMethodsDidFailWithError:error];
}
#end
Put your viewController conform to the WebServiceMethodsDelegate protocol.
#interface yourViewController : UIViewController <WebServiceMethodsDelegate>
...
#end
and know in your the viewDidLoad of your viewController :
WebServiceMethods *web=[[WebServiceMethods alloc]init];
web.delegate = self;
[web RequestForData];
Put also the delegate methods in viewController.m
- (void)webServiceMethodsDidFinishWithSucess:(NSString *)response {
// here you can parse the response and reload your tableView
.....
[self.tableView reloadData];
}
- (void)webServiceMethodsDidFailWithError:(NSError *)error {
// handle the errors
}
PS : There are many problems with your code :
Don't use ASHTTPRequest, it's not maintained. You can use AFNetworking.AFNetworking
Put your WebServiceMethods as a shared instance.
....
I currently have a class and ViewController with a button action to get the username and password from a textfield and put them into their own NSString. I then use the NSString to perform a post request like so.
NSString *user = _username.text;
NSString *password = _password.text;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:#"http://thesite.com/login.php"]];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
NSMutableURLRequest *request = [httpClient requestWithMethod:#"POST"
path:#"http://thesite.com/login.php"
parameters:#{#"username":user, #"password":password}];
AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
//success code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handler
}];
[httpClient enqueueHTTPRequestOperation:httpOperation];
However I have another class and Viewcontroller to perform a get request. However, in order to perform this get request I need to get the "NSString *user" from the first View Controller. How would I go about doing this? Should I declare a NSString *user in the header of the first Viewcontroller and then in the second View controller declare an instance of the first class?
You can pass strings through viewcontrollers. Make therefore a segue between the two viewcontroller and named it for example "secondVC"
the when you want to switch to other view make this call
[self performSegueWithIdentifier:#"secondVC"];
and implement this method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"secondVC"]) {
SecondViewController *second = (SecondViewController *)[segue destinationViewController];
second.userString = self.user;
}
}
You can use NSUserDefaults to store the username and use it in other ViewControllers.
For example, save it in your current ViewController.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:username forKey:#"UserName"];
[defaults synchronize];
get username it in another ViewController.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *username = [defaults objectForKey:#"UserName"];
pass the userName to second view controller.
You can achieve it using following approaches.
try to pass the username when you are initialising your secondViewController like
SecondViewController * sVC = [SecondViewController alloc] initWithUserName: username];
for this in your SecondViewController class you have to modify the init method and add a property of userName {typeOF string}
#property (nonatomic, strong) NSString * userName
- (id) initWithUserName: (NSString *) name
{
self = [super initWithNibName: #"SecondViewController"
bundle: nil];
if (self)
{
self.userName = name;
}
return self;
}
Enjoy!!
Create object of first class in second class like this..
//First class
//Pass the values to seconClass
secondClass *appdelegate = [NSApp delegate];
[appdelegate initwithDetails:userName withPassword:password];
//Second class
//In second class declare the function and get the values
//When u create the object, init function will call first
-(id)initwithDetails:(NSString *)user withPassword:(NSString *)password
{
userName = [NSString stringWithFormat:#"%#", user];
newPass=[NSString stringWithFormat:#"%#", password];
return self;
}
If the second viewcontroller is spawned from the first you could just create a delegate protocol and corresponding delegate so that either the first is delegate of the second or the second is delegate of the first:
Here is an example of a protocol which includes one method, notice the instance variable delegate is of type id, as it will be unknown at compile time the type of class that will adopt this protocol.
#import <Foundation/Foundation.h>
#protocol ProcessDataDelegate <NSObject>
#required
- (void) processSuccessful: (BOOL)success;
#end
#interface ClassWithProtocol : NSObject
{
id <ProcessDataDelegate> delegate;
}
#property (retain) id delegate;
-(void)startSomeProcess;
#end
Inside the implementation section for the interface defined above we need to do two things at a minimum – first synthesize the delegate instance variable and second, call the method defined in the protocol as needed (more on that in a moment).
Let’s look at a bare bones implementation of the ClassWithProtocol.m:
#import "ClassWithProtocol.h"
#implementation ClassWithProtocol
#synthesize delegate;
- (void)processComplete
{
[[self delegate] processSuccessful:YES];
}
-(void)startSomeProcess
{
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:#selector(processComplete) userInfo:nil repeats:YES];
}
#end
Read more at this tutorial
I read allot about the SplitViewControllers but i am walking in circles because i dont understand something.
You have a masterviewcontroller and a popoverview as a bar button item (filter)
lets say masterviewcontroller is a tableview and in the popoverview is a uiview controller
On the iphone i always alloced the masterviewcontroller and update the reference after some modifications, when you hit the button "search", it pushed a new controller with new data (come to think of it,maybe this wasnt the best idea) now that logic doesnt work anymore.
I have read you have to reference the controllers to each other, so i did it like this.
in the filtercontroller (this is the popoverview)
.h
#property (strong, nonatomic) MasterViewController *masterviewController;
#property (weak, nonatomic) IBOutlet UISlider *filterPrice;
- (IBAction)filterSearch:(id)sender;
.m
- (IBAction)filterSearch:(id)sender {
self.masterviewController.filterSearchPrice = [NSNumber numberWithInt:self.filterPrice.value];
[self.masterviewController performFilterSearch];
}
the performFilterSearch checks the fields, makes a call to an url with the filternames and json objects come back,parse and reload data happens..
Now i expect the masterviewcontroller to show new data but that doesnt happen, in fact nothing happens...
Update this is FilterSearch:
-(void)performFilterSearch
{
[queue cancelAllOperations];
[[AFImageCache sharedImageCache] removeAllObjects];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
isLoading =YES;
[self.tableView reloadData];
searchResults = [NSMutableArray arrayWithCapacity:10];
NSURL *url = [self urlFilterWithSearchPrice:filterSearchPrice];
NSLog(#"%#",url);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self parseDictionary:JSON];
isLoading = NO;
[self.tableView reloadData];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
[self showNetworkError];
isLoading = NO;
[self.tableView reloadData];
}];
operation.acceptableContentTypes = [NSSet setWithObjects:#"application/json", #"text/json", #"text/javascript",#"text/html", nil];
[queue addOperation:operation];
}
btw when i Nslog in filterSearch to check if its updated:
NSLog(#"%d",self.masterviewController.filterSearchPrice);
NSLog(#"%d",[self.filterTypeSegmentedControl selectedSegmentIndex]);
the first one never gets updated the second one gets updated off course
Update 2: (how do i launch the popview):
I added a bar button item on the masterviewcontrollers navigation that has an action.
I added a popover segue from the masterviewcontroller -> filtercontroller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
filterPopOver = [(UIStoryboardPopoverSegue *)segue popoverController];
}
- (IBAction)filterPopButton:(id)sender {
if (filterPopOver){
[filterPopOver dismissPopoverAnimated:YES];
}
else{
[self performSegueWithIdentifier:#"showFilterPopover" sender:sender];
}
}
When you launch your filterController, you need to pass in a reference to the MasterViewController. You have a property for it in the filter controller, but you never assign a value to that property.
After Edit:
Your prepareForSegue method should look like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
FilterController *fc = (FilterController *)segue.destinationViewController;
fc.masterViewController = self;
}
Make sure that you've imported MasterViewController.h into you FilterController.m