7

我正在构建一个 UIView,它连接到包含商店商品列表的 UITableView,并由与对象类(shopObjects)关联的数据数组填充。

这是我的商店物品 H 文件 -

#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

商店对象。文件

#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

这是我的视图控制器 .h 文件 -

#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

和 VC .m 文件 -

#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

我正在尝试将标签/文本字段与相关对象变量链接起来——但 shopObjects 对象/关联变量没有出现在预测文本中,并且我得到以下属性未找到错误——我不知道为什么!有人可以提供一些建议吗?

在此处输入图像描述

4

4 回答 4

7

你没有继承shopObjects你的 viewController。它是一个单独的对象。您需要创建一个类型的变量shopObjects,设置其属性,然后调用它。例如

shopVcSelectionViewController.h

@property (strong, nonatomic) shopObjects *shopObject;




shopVcSelectionViewController.m

...
self.shopItemTitle.text = self.shopObject.shopTitle
...
于 2013-10-18T11:09:07.703 回答
1

如果您有一个与类同名的对象实例,并且您错误地对类进行操作,而不是您的实例(感谢 Xcode 自动完成),您也会看到此错误。

例如,假设您有一个视图控制器SetSignsViewController,并且您创建了一个名为的视图控制器实例setSignsViewController

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

您想设置一个名为的属性的名称openHouseLocation

SetSignsViewController.openHouseLocation = self.openHouseLocation;

这会产生Property 'openHouseLocation' not found on object of type 'SetSignsViewController',因为您正在操作SetSignsViewController, not setSignsViewController(第一个字母应该是s, not S)。你真正想做的是:

setSignsViewController.openHouseLocation = self.openHouseLocation;
于 2015-03-19T17:08:55.660 回答
1

您发布的代码位于 shopSelectionViewController 类的实例方法中。shopSelectionViewController 具有属性 shopItemTitle,但没有 shopITitle 属性。

这条线

self.shopItemTitle.text = self.shopITitle;

没有意义。

如果您试图从“shopObjects”类的对象中获取标题,那么您需要这样的东西:

shopObjects *someShopObject = //code to fetch a shopObject
self.shopItemTitle.text = someShopObject.shopITitle;
于 2013-10-18T11:35:59.340 回答
-1

尝试使用@synthesizeShopObjects 的 .m 文件中的变量。

于 2013-10-18T11:03:49.960 回答