所以我有一个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;
}
@end
PersonData.h代码: #import
@interface PersonData : NSObject
@property (strong) NSString *name;
@property (assign) NSString *gift;
- (id)initWithTitle:(NSString*)name gift:(NSString*)gift;
@end
PersonData.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
在我的viewcontroller中,我收到一条错误,说明在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吗?谢谢,我非常感谢任何帮助人员!
答案 0 :(得分:0)
根据您发布的代码,标头和实现中的initWithTitle
具有不同的签名。解决这个问题,你的警告应该消失