From my MCSettingsFormViewController, I want to set MatchCenterViewController's didAddNewItem BOOL property, but without making use of a segue.
I've imported MatchCenterViewController.h, which contains that property like so:
#property (assign) BOOL didAddNewItem;
However, when I try to set it like this: MatchCenterViewController.didAddNewItem = YES;, it says "property didAddNewItem not found on object of type 'MatchCenterViewController'".
I assume this is because I haven't defined what MatchCenterViewController is. If so, how can I do this property so it sets the property correctly?
edit:
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#import "WebViewController.h"
#import "WSCoachMarksView.h"
#import "SLExpandableTableView.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (strong, nonatomic) NSString *itemSearch;
#property (strong, nonatomic) NSString *itemPriority;
//#property (strong, nonatomic) IBOutlet UITextField *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#property (strong, nonatomic) NSString *matchingCategoryCondition;
#property (strong, nonatomic) NSString *matchingCategoryLocation;
#property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryId;
#property (strong, nonatomic) NSArray *matchCenterArray;
#property (strong, nonatomic) NSString *searchTerm;
#property (strong, nonatomic) NSString *itemURL;
#property (assign) NSInteger expandedSection;
#property (assign) NSInteger rowCount;
#property (assign) BOOL didAddNewItem;
#property (assign) BOOL results;
#property (strong, nonatomic) IBOutlet UIButton *editButton;
#property (weak, nonatomic) IBOutlet UIButton *moreButton;
#property (strong) NSMutableSet *expandedSections;
#end
#interface MoreButton : UIButton
#property (assign) NSInteger expandedSection;
#property (assign) NSInteger sectionIndex;
#end
MCSettingsFormViewController.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <Parse/Parse.h>
#import "MatchCenterViewController.h"
#interface MCSettingsFormViewController : UIViewController
#property (strong, nonatomic) NSString *minPrice;
#property (strong, nonatomic) NSString *maxPrice;
#property (strong, nonatomic) NSString *itemCondition;
#property (strong, nonatomic) NSString *itemLocation;
#property (strong, nonatomic) NSString *searchTerm;
#property (strong, nonatomic) NSString *itemPriority;
#property (strong, nonatomic) IBOutlet UITextField *tf;
#property (strong, nonatomic) IBOutlet UITextField *tf1;
#property (strong, nonatomic) IBOutlet UITextField *tf2;
#end
You need to use an instance of MatchCenterViewController not the name of the class. Presumably, somewhere in your app there's a reference to a MatchCenterViewController object. You can either access that reference or pick a different way of letting it know about the change.
For example, if your two controllers aren't connected to each other, you could post a notification in MCSettingsFormViewController and react to it in MatchCenterViewController.
For more specific suggestions, I'd need to know how both controllers are created and presented.
When you instantiate MatchCenterViewController, you could set it as a delegate of MCSettingsFormViewController. That way, the MatchCenterViewController defines itself as the instantiated version of the class to be edited by the MatchCenterViewController.
Here is a basic tutorial for delegates: http://www.tutorialspoint.com/ios/ios_delegates.htm
So based off of your headers, it looks like either your MCSettingsFormViewController doesn't have a property of type MatchCenterViewController-- or that property is private.
In the former case, you need to add a property to your MCSettingsFormViewController with type MatchCenterViewController.
In the latter you aren't initializing your MatchCenterViewController property.
So first, make sure you have that public/private property.
Then, when you first create and show your SettingsFormViewController, set this property to your MatchCenterViewController instance. Now your SettingsForm has a reference to the proper instance you're looking for.
At this point, you can set the property on the MatchCenter
Related
these 2 are the files where i m creating a protocol and then declare the delegate in another class
this is my favouriteViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"
#class FavouritesTableViewController;
#protocol FavouritesTableViewControllerDelegate<NSObject>
- (void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item;
#end
#interface FavouritesTableViewController : UITableViewController <UISearchControllerDelegate,UISearchBarDelegate>
#property (strong, nonatomic) IBOutlet UISearchController *search;
#property (strong, nonatomic) IBOutlet UITableView *table;
#property (nonatomic, weak) id < FavouritesTableViewControllerDelegate > delegate;
#end
and this is my viewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "FavouritesTableViewController.h"
#interface ViewController : UIViewController <CLLocationManagerDelegate,FavouritesTableViewControllerDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *weatherIcon;
#property (weak, nonatomic) IBOutlet UILabel *Place;
#property (weak, nonatomic) IBOutlet UILabel *Temperature;
#property (weak, nonatomic) IBOutlet UILabel *unit;
#property (weak, nonatomic) IBOutlet UILabel *weatherText;
#property (weak, nonatomic) IBOutlet UITextView *Info;
#property (weak, nonatomic) IBOutlet UILabel *summary;
#property (strong,nonatomic) NSString *longitude;
#property (strong,nonatomic) NSString *latitude;
#property (strong,nonatomic) NSString *locationName;
#property BOOL setLocation;
#property (weak, nonatomic) IBOutlet UIScrollView *scroll;
- (IBAction)forecast:(UIButton *)sender;
- (IBAction)Share:(UIButton *)sender;
- (IBAction)history:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activIndicator;
- (IBAction)favbutton:(id)sender;
#end
the error i get is
:- Cannot find protocol declaration for
'FavouritesTableViewControllerDelegate'
I'm declaring these methods and protocols to pass data from FavouriteViewController to ViewController
and this is the protocol method which i call in ViewController.m
-(void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item
{
controller.delegate = self;
self.latitude = [item[0] valueForKey:#"lat"];
self.longitude = [item[0] valueForKey:#"long"];
self.locationName = [item[0] valueForKey:#"name"];
self.setLocation = YES;
[self viewDidLoad];
}
Ths is happening because of recursive import, in FavouritesTableViewController you are importing "ViewController.h" and again ViewController.h you are importing "FavouritesTableViewController.h"
try
#class viewController;
#class FavouritesTableViewController;
in FavouritesTableViewController.h and remove "#import ViewController.h"
I have a view controller HomeController & BookController.I am going from view controller HomeController to BookController.I am passing data back to previous view controller.So i have used this approach.
#import <UIKit/UIKit.h>
#import "BaseController.h"
#import <MediaPlayer/MediaPlayer.h>
#protocol HomeProtocol
- (void)setComment:(BOOL)data;
-(void)setCommnetArray:(NSMutableArray*)data;
#end
#protocol BookProtocol
-(void)setBook:(BOOL)status;
#end
#interface HomeViewController : BaseController<UITableViewDataSource,UITableViewDelegate,HomeProtocol,UIScrollViewDelegate,BookProtocol,UINavigationControllerDelegate>
#property (weak, nonatomic) IBOutlet UITableView *table_view;
#property BOOL hasUserPostedComment;
#property NSInteger commentIndex;
#property (weak, nonatomic) IBOutlet UILabel *label_post_status;
#property UIRefreshControl *refreshControl;
#property NSInteger start_offset;
#property NSInteger end_offset;
#property (weak, nonatomic) IBOutlet UIButton *btn_refresh;
#property NSMutableArray *temp_user_cooments;
#property MPMoviePlayerController *moviePlayerController;
#property BOOL isBookMarkLoaded;
#end
BookMarkController.h
#import <UIKit/UIKit.h>
#import "BaseController.h"
#import "HomeViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#protocol HomeProtocol
- (void)setComment:(BOOL)data;
-(void)setCommnetArray:(NSMutableArray*)data;
#end
#interface BookMarkController : BaseController<UITableViewDataSource,UITableViewDelegate,HomeProtocol,UIScrollViewDelegate>
#property (nonatomic, weak) id<BookProtocol> myDelegate;
#property (weak, nonatomic) IBOutlet UITableView *table_view;
#property BOOL hasUserPostedComment;
#property NSInteger commentIndex;
#property (weak, nonatomic) IBOutlet UILabel *label_post_status;
#property UIRefreshControl *refreshControl;
#property NSInteger start_offset;
#property NSInteger end_offset;
#property (weak, nonatomic) IBOutlet UIButton *btn_refresh;
#property NSMutableArray *temp_user_cooments;
#property MPMoviePlayerController *moviePlayerController;
#property NSString *index;
#end
Method implementation
-(void)setBook
{
NSLog(#"set book called");
self.isBookMarkLoaded=true;
}
It gives error Unrecognized selector sent to instance.Please tell me what is the issue here.
#protocol BookProtocol
-(void)setBook:(BOOL)status;
#end
Add above protocol to BookMarkController.h. Create delegate of the same in BookMarkController.h file. Make a call to -(void)setBook:(BOOL)status; from BookMarkController.m file
Add delegate in HomeViewController.h file. Define -(void)setBook:(BOOL)status; in HomeViewController.m file and also assign delegate to self.
That's all.
So I have this -
#import <UIKit/UIKit.h>
#import "RateView.h"
#interface BasicCardViewController : UIViewController<RateViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *label;
#property(copy, nonatomic)NSString *message;
#property(atomic)NSInteger rating;
#property (strong, nonatomic) IBOutlet RateView *rateView;
#property (weak, nonatomic) IBOutlet UILabel *ratingLabel;
#end
and this - in my RateView.h file.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#class RateView;
#protocol RateViewDelegate
-(void)rateView:(RateView *)rateView ratingDidChange:(float)rating;
#end
#interface RateView : UIView
#property(strong,nonatomic)UIImage* fullSelectedStar;
#property(strong,nonatomic)UIImage* notSelectedStar;
#property(strong, nonatomic)UIImage* halfSelectedStar;
#property (assign, nonatomic)float rating;
#property(assign) BOOL editable;
#property (strong) NSMutableArray* imageViews;
#property(assign,nonatomic) int maxRating;
#property(assign) int midMargin;
#property(assign)int leftMargin;
#property (assign) CGSize minImageSize;
#property (assign) id <RateViewDelegate> delegate;
#end
But I get two errors -
1.Cannot find protocol declaration for 'TooviaRateViewDelegate'
2.Unknown type name "RateView"
I've tried to clean, and I've verified that the files are where they should be (their filepaths are to the project).
Why is this happening?
Edit - my AppDelegate.h
#import <UIKit/UIKit.h>
#import "SearchViewController.h"
#interface TooviaAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property NSOperationQueue *queue;
#property (strong, nonatomic) NSDictionary *userProfile;
#property (strong, nonatomic) SearchViewController *searchViewController;
- (NSOperationQueue*) getOperationQueue;
- (id)getSettings:(NSString *)keyPath;
- (void) saveCookies;
#end
There are also issues in my SearchViewController
#import <UIKit/UIKit.h>
#import "BasicCardViewController.h"
#interface SearchViewController : UIViewController
<UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate>
- (IBAction)searchButtonClicked:(UIButton *)sender;
- (IBAction)backgroundTap:(id)sender;
#property (weak, nonatomic) IBOutlet UITableView *resultTable;
#property (weak, nonatomic) IBOutlet UITextField *searchBar;
#property (strong, nonatomic) NSArray *resultsTuples;
#property (weak, nonatomic) IBOutlet UIButton *searchButton;
#property (copy, nonatomic) NSArray *controllers;
#property(strong,nonatomic)BasicCardViewController *detailController;
Delegate and data source properties are usually marked as weak for the object graph management reasons described earlier, in “Avoid Strong Reference Cycles.”
I have this Json out of ASP MVC API
I have the InvModel and the LotModel
but when I call
_InvFeed = [[InvModel alloc] initFromURLWithString:#"http://192.168.1.206/service/api/dto/inventory/1?p=Red%20Globe"
completion:^(JSONModel *model, JSONModelError *err)
{
NSLog(#"Inventory: %#", _InvFeed );
NSLog(#"Error: %#",err);
}];
I can not figure out this error:
Error: Error Domain=JSONModelErrorDomain Code=1 "Invalid JSON data:
Attempt to initialize JSONModel object using initWithDictionary:error:
but the dictionary parameter was not an 'NSDictionary'."
UserInfo=0x109075ff0 {NSLocalizedDescription=Invalid JSON data:
Attempt to initialize JSONModel object using initWithDictionary:error:
but the dictionary parameter was not an 'NSDictionary'.,
kJSONModelKeyPath=LotDTO}
and here are the JSONModels for: LotDTO
#import "JSONModel.h"
#interface InvLotModel : JSONModel
#property (assign, nonatomic) int lotid;
#property (strong, nonatomic) NSDate* expdate;
#property (strong, nonatomic) NSString* lotserial;
#property (strong, nonatomic) NSDate* lastupddate;
#property (strong, nonatomic) NSString<Optional>* providerlotserial;
#property (assign, nonatomic) NSDecimal* qtyoriginal;
#property (assign, nonatomic) NSDecimal* qtyallocated;
#property (assign, nonatomic) NSDecimal* qtyavailable;
#property (assign, nonatomic) NSDecimal* qtyonhand;
#property (strong, nonatomic) NSDate* receiptdate;
#property (strong, nonatomic) NSString* linecomment;
#property (assign, nonatomic) NSDecimal* unitcost;
#property (strong, nonatomic) NSString* warehouse;
#end
And here the Inventory Model
#import "JSONModel.h"
#import "InvLotModel.h"
#protocol InvModel #end
#interface InvModel : JSONModel
#property (assign, nonatomic) int id;
#property (strong, nonatomic) NSString* itemid;
#property (strong, nonatomic) NSString* description;
#property (strong, nonatomic) NSDate* createdate;
#property (strong, nonatomic) NSString* createuser;
#property (assign, nonatomic) float lastcost;
#property (assign, nonatomic) BOOL monitorlevel;
#property (assign, nonatomic) int minlevel;
#property (assign, nonatomic) int maxlevel;
#property (strong, nonatomic) NSString* gtin;
#property (assign, nonatomic) float weight;
#property (strong, nonatomic) NSString* uom;
#property (strong, nonatomic) NSString* sizes;
#property (strong, nonatomic) NSString* variety;
#property (strong, nonatomic) NSString <Optional>* bag;
#property (strong, nonatomic) NSString* style;
#property (strong, nonatomic) NSString* box;
#property (strong, nonatomic) NSString* label;
#property (strong, nonatomic) NSString* commodity;
#property (strong, nonatomic) InvLotModel* LotDTO;
#end
I see two problems:
1) In the InvModel class, yo have defined LotDTO as a single object, not an array.
2) In the JSON response you have posted, the syntax for LotDTO does not seem to me valid JSON. It appears to be an array of LotDTO objects, but it does not follow the syntax for JSON arrays (which you can check, for example, here).
Make sure to mark any extension property as Ignore. I faced such an issue trying to copy the model.
Please replace this
#property (strong, nonatomic) InvLotModel* LotDTO;
with this
#property (strong, nonatomic) NSArray<InvLotModel,ConvertOnDemand>* LotDTO;
As officials at JSONModel suggest to use ConvertOnDemand to convert NSArray to JSONModelArray in one of their tutorial to avoid error in implenentation.
This may help you : Click here
I declare my .h file like this:
#import <UIKit/UIKit.h>
#interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
NSArray *questionTitleTrip;
NSArray *questionDescTrip;
NSMutableArray *answerTrip;
NSMutableArray *pickerChoices;
int questionInt;
int totalInt;
IBOutlet UILabel *questionNum;
IBOutlet UILabel *questionTotalNum;
IBOutlet UILabel *recordType;
IBOutlet UITextView *questionDes;
IBOutlet UIView *answerView;
IBOutlet UIButton *preButton;
IBOutlet UIButton *nextButton;
UITextField *text;
UIPickerView *picker;
}
#property (retain, nonatomic) NSArray *questionTitleTrip;
#property (retain, nonatomic) NSArray *questionDescTrip;
#property (retain, nonatomic) NSMutableArray *answerTrip;
#property (retain, nonatomic) NSMutableArray *pickerChoices;
#property (retain, nonatomic) IBOutlet UILabel *questionNum;
#property (retain, nonatomic) IBOutlet UILabel *questionTotalNum;
#property (retain, nonatomic) IBOutlet UILabel *recordType;
#property (retain, nonatomic) IBOutlet UITextView *questionDes;
#property (retain, nonatomic) IBOutlet UIView *answerView;
#property (retain, nonatomic) IBOutlet UIButton *preButton;
#property (retain, nonatomic) IBOutlet UIButton *nextButton;
#property (retain, nonatomic) UITextField *text;
#property (retain, nonatomic) UIPickerView *picker;
-(IBAction)clickPre;
-(IBAction)clickNext;
#end
And my .m file here like this:
#import "NavigationTripViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface NavigationTripViewController ()
#end
#implementation NavigationTripViewController
#synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker;
All my variables in the #synthesize receive the warnings:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'
Also, the variables and class names used in viewDidLoad don't display in colors, just show in black color. In other view controllers, there are no warnings like this. How to fix these problems?
Edit:
Basically for all intents and purposes you should be building on a new enough XCode to use the new behavior, in that solution you typically will just remove the ivar from the #interface block in the .h file... If for some reason you do need to access an ivar directly you can now declare it in the #implementation block... and use #synthesize var or #synthesize var=_var
OGPost:
to make that go away you can go all new school and drop the iVar, or you can go all old school and add an #synthesize someIvar in your #implementation block.