2012-12-05 26 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類中 –