Objective C - IOS - property not found on an object of type - when accessing object variables

I create a UIView that is connected to a UITableView containing a list of store items, and is populated with an array of data that is associated with an object class (shopObjects).

here is my object H store objects -

#import <Foundation/Foundation.h> @interface shopObjects : NSObject @property(strong) NSString *shopITitle; @property(strong) NSString *shopIGroup; @property(strong) NSString *shopIDesc; @property(strong) NSString *shopIPrice; @property Boolean offer; -(id)initWithshopITitle:(NSString *)shopITitleD shopIGroup:(NSString *)shopIGroupD shopIDesc: (NSString *)shopIDescD shopIPrice:(NSString *)shopIPriceD offer:(Boolean )offerD; @end 

The object of the store. M file

 #import "shopObjects.h" @implementation shopObjects -(id)initWithshopITitle:(NSString *)shopITitleD shopIGroup:(NSString *)shopIGroupD shopIDesc:(NSString *)shopIDescD shopIPrice:(NSString *)shopIPriceD offer:(Boolean )offerD{ self= [super init]; if(self){ self.shopITitle = shopITitleD; self.shopIGroup = shopIGroupD; self.shopIDesc = shopIDescD; self.shopIPrice = shopIPriceD; self.offer = (offerD); } return self; } @end 

This is my .h file controller.

 #import <UIKit/UIKit.h> #import "shopObjects.h" @interface shopVCSelectionViewController : UIViewController @property (weak, nonatomic) IBOutlet UIScrollView *shopResScroller; @property (weak, nonatomic) IBOutlet UILabel *ShopItemTitle; @property (weak, nonatomic) IBOutlet UITextView *ShopItemDesc; @property (weak, nonatomic) IBOutlet UILabel *ShopItemPrice; @end 

and the VC.m file -

 #import "shopVCViewController.h" @interface shopVCViewController () @end @implementation shopVCViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //Set Scroller [self.shopScroll setScrollEnabled:YES]; [self.shopScroll setContentSize:CGSizeMake(320, 1100)]; self.title = @"Shop"; self.shopArray = [NSArray arrayWithObjects:@"1 x PT session - Β£25",@"3 for 2 PT sessions - Β£50 ",@"1 x Running Club - Β£15",@"1 x PT session", nil]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.shopArray count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier =@ "Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; cell.textLabel.text=[self.shopArray objectAtIndex:indexPath.row]; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

I am trying to associate labels / text fields with the corresponding object variables, but the object or related shopObjects / objects are not displayed in the predictive text, and I get the following property: no error was found - I have no idea why! Can someone offer some advice please?

enter image description here

+6
source share
4 answers

You did not inherit shopObjects in your viewController. This is a separate facility. You need to create a variable of type shopObjects , set its properties and then call it. eg

 shopVcSelectionViewController.h @property (strong, nonatomic) shopObjects *shopObject; shopVcSelectionViewController.m ... self.shopItemTitle.text = self.shopObject.shopTitle ... 
+5
source

The code you submitted is in the instance method of the shopSelectionViewController class. ShopSelectionViewController has the propertyItemTitle property, but not the shopITitle property.

This line

 self.shopItemTitle.text = self.shopITitle; 

It makes no sense.

If you are trying to get the title from an object of class "shopObjects", you will need something like this:

 shopObjects *someShopObject = //code to fetch a shopObject self.shopItemTitle.text = someShopObject.shopITitle; 
+1
source

Try the @synthesize variables in the .m ShopObjects file.

0
source

You will also see this error if you have an instance of an object with the same name as the class and you are mistakenly working with the class and not with your instance (thanks, Xcode autocopy).

For example, suppose you have a SetSignsViewController view controller and you create an instance of a view controller named SetSignsViewController :

 SetSignsViewController *setSignsViewController = (SetSignsViewController *) uiNavigationController.topViewController; 

You want to set the property name with the name openHouseLocation :

 SetSignsViewController.openHouseLocation = self.openHouseLocation; 

This gives Property 'openHouseLocation' not found on object of type 'SetSignsViewController' because you are working with SetSignsViewController and not SetSignsViewController . What you really wanted to do is:

 SetSignsViewController.openHouseLocation = self.openHouseLocation; 
0
source

Source: https://habr.com/ru/post/956230/


All Articles