Iphone 向UITableView子类添加属性
我正在创建Iphone 向UITableView子类添加属性,iphone,ios,objective-c,cocoa-touch,uitableview,Iphone,Ios,Objective C,Cocoa Touch,Uitableview,我正在创建UITableViewCell子类,它需要保存3种类型的图像:facebook、twitter和linkedin。问题是,我需要知道cell目前支持哪种服务,因此我尝试向名为service的类添加一个属性,即NSString 以下是我如何设置手机以将其添加到表中: static NSString *sCellIdentifier = @"sCell"; SocialTableViewCell *sCell = [tableView dequeueReusableCellWithIde
UITableViewCell
子类,它需要保存3种类型的图像:facebook、twitter和linkedin。问题是,我需要知道cell目前支持哪种服务,因此我尝试向名为service
的类添加一个属性,即NSString
以下是我如何设置手机以将其添加到表中:
static NSString *sCellIdentifier = @"sCell";
SocialTableViewCell *sCell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
sCell.service = @"service";
if (sCell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ExampleView" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[SocialTableViewCell class]])
{
sCell = (SocialTableViewCell *)currentObject;
break;
}
}
}
if (indexPath.row == 0) {
sCell.serviceImage.image = [UIImage imageNamed:@"icon_Twitter.png"];
sCell.service = @"twitter";
return sCell;
}
我正在尝试如下设置属性:
sCell.service = @"twitter";
当我试图从
SocialTableViewCell
类中的awakeFromNib
方法中读取它时,我得到null。我应该怎么做才能管理它?在设置服务
属性之前,会调用awakeFromNib
方法
您可以使用服务
属性的setter方法:
-(void) setService:(NSString *)service {
// Set the value to the internal iVar
_service = service;
// Here you can do what you want with the service value like
self.titleLabel.text = service;
}
在设置
服务
属性之前,将调用awakeFromNib
方法。好的,我应该使用什么方法?我在哪里可以读到它?你可以为服务属性创建一个setter方法并在那里处理它。我认为你应该有一个.m.h的自定义单元格并在那里处理它谢谢!我应该在哪里检查实例的值?与UIViewControllery中的“viewdidload”方法类似,您也可以在setter中执行此操作。视图没有viewDidLoad
。我正在尝试从该属性所包含的值加载按钮状态。。。所以我有一些“loadButtons”方法,我想调用,只是从setter方法调用它。