Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm building a UIView which is connected to a UITableView containing a list of shop items and populated by an array of data which is associated to an object class (shopObjects).

here is my shop objects H file -

#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

Shop Object . 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 view controller .h file -

#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 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 link up the labels/text fields with the relevant object variables - but the shopObjects object / associated variables dont appear in the predictive text and I get the following property not found error - I've no idea why! Can anyone offer some advice please?

enter image description here

like image 909
Dancer Avatar asked Oct 18 '13 11:10

Dancer


2 Answers

You did not inherit shopObjects in your viewController. It is a separate object.You need to create a variable of type shopObjects, set its properties and then call that. e.g.

shopVcSelectionViewController.h

@property (strong, nonatomic) shopObjects *shopObject;




shopVcSelectionViewController.m

...
self.shopItemTitle.text = self.shopObject.shopTitle
...
like image 110
Simon McLoughlin Avatar answered Oct 29 '22 20:10

Simon McLoughlin


The code you posted is in an instance method of the class shopSelectionViewController. A shopSelectionViewController has a property shopItemTitle, but not a shopITitle property.

This line

self.shopItemTitle.text = self.shopITitle;

Does not make sense.

If you are trying to fetch a title from an object of class "shopObjects", then you would need something like this:

shopObjects *someShopObject = //code to fetch a shopObject
self.shopItemTitle.text = someShopObject.shopITitle;
like image 21
Duncan C Avatar answered Oct 29 '22 20:10

Duncan C