7

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

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Dancer
  • 17,035
  • 38
  • 129
  • 206
  • Are the propertied connected to the UI objects in Interfacebuilder? BTW, the Apple naming conventions in Objective-C are for classes to start with a capital letter. – zaph Oct 18 '13 at 11:04
  • 1
    Please copy/paste the (relevant) code instead of screenshots. That makes it much easier for others to search for potential problems in your code. – Martin R Oct 18 '13 at 11:06
  • I cannot see a property `shopITitle` in your *view controller*... – Martin R Oct 18 '13 at 11:07
  • It seems that there is no shopITitle property in your shopVCSelectionViewController. Also, use lowercase for property names and in your init use _propertyName = propertyValue. – Cyupa Oct 18 '13 at 11:09
  • There is no property for ShopTitle in the viewController – Tendulkar Oct 18 '13 at 11:14
  • thanks guys - that screenshot was confusingly misleading - ive added the actual code - for some reason I cant access the shopObjects object or its properties in my .m file despite its header file being included.. – Dancer Oct 18 '13 at 11:22
  • note taken @Zaph re the naming conventions - out of interest would Apple be picky enough to reject and app for that - or is its simply a standard to stick to? – Dancer Oct 18 '13 at 11:26
  • 1
    No, Apple will not reject an app but there are two main reasons for following conventions: 1) To others can easily understand your code. 2) The LLVM compiler and analyzer rely on certain naming conventions for error/warning messages and ARC. – zaph Oct 18 '13 at 12:43

4 Answers4

7

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
...
Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56
1

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;
Duncan C
  • 128,072
  • 22
  • 173
  • 272
1

You'll also see this error if you have an object instance which is the same name as a class, and you mistakenly operate on the class, not your instance (thanks, Xcode auto-complete).

For example, suppose that you have a view controller SetSignsViewController and you create an instance of the view controller called setSignsViewController:

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

You want to set the name of a property called openHouseLocation:

SetSignsViewController.openHouseLocation = self.openHouseLocation;

This yields Property 'openHouseLocation' not found on object of type 'SetSignsViewController' because you're operating on SetSignsViewController, not setSignsViewController (first letter should be s, not S). What you really meant to do was:

setSignsViewController.openHouseLocation = self.openHouseLocation;
Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
-1

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

Tendulkar
  • 5,550
  • 2
  • 27
  • 53
  • 5
    Since Xcode 4.4 (LLVM Compiler 4.0) the properties are synthesized automatically by the compiler, if necessary. – Martin R Oct 18 '13 at 11:09