2012-12-05 22 views
2

所以我有下面的代码PersonDoc.h文件:initWithTitle会使未实现

#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代码: #进口

@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和做initWithTitle。 m文件?谢谢,我非常感谢任何帮助人!

回答

0

根据您发布的代码,您的页眉和实现中的initWithTitle具有不同的签名。解决这个问题,你的警告应该消失

+0

哇蠢的错误,谢谢!但是,我遇到了一个新的错误,特别是在PersonDoc对象中找不到的属性'name'和'gift'。 – Mwoo

+0

同样,您发布的代码在PersonData类中有两个属性,而不是在PersonDoc类中 –