因此,我有一个包含以下代码的PersonDoc.h文件:
#import <Foundation/Foundation.h>
@class PersonData;
@interface PersonDoc : NSObject
@property (strong) PersonData *data;
@property (strong) UIImage *thumbImage;
- (id)initWithTitle:(NSString*)name gift:(NSString*)gift thumbImage:(UIImage *)thumbImage;然而,我的PersonDoc.m文件总是给我一个警告符号,告诉我实现不完整。下面是.m代码:
#import "PersonDoc.h"
#import "PersonData.h"
@implementation PersonDoc
@synthesize data = _data;
@synthesize thumbImage = _thumbImage;
- (id)initWithTitle:(NSString*)title gift:(NSString *)gift thumbImage:(UIImage *)thumbImage fullImage:(UIImage *)fullImage {
if ((self = [super init])) {
self.data = [[PersonData alloc] initWithTitle:title gift:gift];
self.thumbImage = thumbImage;
}
return self;
}
@endPersonData.h代码:#import
@interface PersonData : NSObject
@property (strong) NSString *name;
@property (assign) NSString *gift;
- (id)initWithTitle:(NSString*)name gift:(NSString*)gift;
@endPersonData.m代码:
#import "PersonData.h"
@implementation PersonData
@synthesize name = _name;
@synthesize gift = _gift;
- (id)initWithTitle:(NSString*)name gift:(NSString*)gift {
if ((self = [super init])) {
self.name = name;
self.gift = gift;
}
return self;
}
@end在我的视图控制器中,我收到一个错误,说在PersonDoc类型的对象上找不到属性名称和礼物。以下代码在我的ViewController中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
// Configure the cell...
// Create the cell
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"PersonCell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"PersonCell"];
}
PersonDoc *person = [self.people objectAtIndex:indexPath.row];
cell.textLabel.text = person.name;
cell.detailTextLabel.text = person.gift;
cell.imageView.image = person.thumbImage;
return cell;
} 我知道这与我的.h文件中的initWithTitle代码有关,所以谁能告诉我如何对我的.h和.m文件执行initWithTitle的正确方法?谢谢,我真的很感谢大家的帮助!
发布于 2012-12-06 05:11:47
头部和实现中的initWithTitle根据您发布的代码具有不同的签名。解决这个问题,你的警告就会消失
https://stackoverflow.com/questions/13732498
复制相似问题