Попробуйте приведенный ниже код. Я немного изменил ваш код, как показано ниже
Поскольку вы можете назначить объект класса Base классу Derived в @synthesize, это может быть достигнуто этим способом, я знаю, что вы уже пробовали это, я пробовал это с помощью приведенного ниже кода и смог получить доступ к переменным с точкой, попробуйте код ниже и дайте мне знать, если он не работает
@interface DerivedCell : BaseCell
{
Derived *derivedObject;
}
@property (nonatomic, retain) Derived *derivedObject;
@end
@implementation DerivedCell
@dynamic derivedObject;
- (void)setDerivedObject:(Base *)baseObj {
if (self.derivedObject == nil) {
derivedObject = [[Derived alloc] init];
}
derivedObject.detailedText = baseObj.title;
}
- (Derived *)derivedObject {
return derivedObject;
}
@interface Derived : Base
{
NSString *detailedText_;
}
@property (nonatomic, retain) NSString *detailedText;
@end
@implementation Derived
@synthesize detailedText = detailedText_;
@end
@interface BaseCell : UITableViewCell
{
Base *baseObj_;
}
@property (nonatomic, retain) Base *baseObj;
@end
@implementation BaseCell
@synthesize baseObj = baseObj_;
@end
@interface Base : NSObject
{
NSString *title_;
}
@property (nonatomic, retain) NSString *title;
@end
@implementation Base
@synthesize title = title_;
@end
Base *b = [[Base alloc] init];
b.title = @"Hello Raj";
BaseCell *bc = [[BaseCell alloc] init];
bc.baseObj = b;
DerivedCell *dc = [[DerivedCell alloc] init];
dc.derivedObject = b;
NSLog(@"Derive dc %@", dc.derivedObject.detailedText);
Другое решение, которое я предоставил, имеет проблему, когда я проверил его
@interface BaseCell : UITableViewCell
{
NSString *baseTitle_;
}
@property (nonatomic, retain) NSString *baseTitle;
@end
@implementation BaseCell
@synthesize baseTitle = baseTitle_;
@end
@interface DerivedCell : BaseCell
{
NSString *derivedTitle_;
}
@property (nonatomic, retain) NSString *derivedTitle;
@implementation DerivedCell
@synthesize derivedTitle = baseTitle;
@end
Когда я создал экземпляр для класса и как показано ниже
DerivedCell *dCell = [[DerivedCell alloc] init];
dCell.baseTitle = @"Hello";
NSLog(@"%@",dCell.baseTitle);//Output was Hello
NSLog(@"%@",dCell.derivedTitle);//Output was (null)
Он не присвоил значение производному заголовку, если он работает для вас, пожалуйста, дайте мне знать
Другое решение с обращением к памяти
@interface BaseCell : UITableViewCell
{
NSMutableString *baseTitle_;
}
@property (nonatomic, retain) NSMutableString *baseTitle;
@end
@implementation BaseCell
@synthesize baseTitle = baseTitle_;
@end
@interface DerivedCell : BaseCell
{
}
@property (nonatomic, retain) NSMutableString *derivedTitle;
@end
@implementation DerivedCell
@synthesize derivedTitle;
- (id) init
{
if ( self = [super init] )
{
baseTitle_ = [[NSMutableString alloc] init];
derivedTitle = baseTitle_;
}
return self;
}
@end
DerivedCell *dCell = [[DerivedCell alloc] init];
[dCell.baseTitle appendString:@"Hello"];
NSLog(@"baseTitle : %@",dCell.baseTitle);
NSLog(@"derivedTitle :%@",dCell.derivedTitle);
Вывод на консоль baseTitle: Hello производныйTitle: Hello