Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 向UITableView子类添加属性_Iphone_Ios_Objective C_Cocoa Touch_Uitableview - Fatal编程技术网

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方法调用它。