Ios 如何获取UITableView标签文本字符串-自定义单元格

Ios 如何获取UITableView标签文本字符串-自定义单元格,ios,objective-c,string,uitableview,Ios,Objective C,String,Uitableview,我有一个CustomCell的UITableView。自定义单元格包含UILabel和UIImageView 我在网上看到,可以从普通的UITableView单元格中获取文本,并在用户按下单元格时将其存储在字符串中 但是,当您使用自定义单元格时,如何做到这一点?因为我的UILabel的名称是“type_label”,它已在我的CustomCell XIB的头文件中定义 所以在Xcode中我不能使用: cell.type_label.text" 在以下功能中: -(void)tableView:

我有一个CustomCell的UITableView。自定义单元格包含UILabel和UIImageView

我在网上看到,可以从普通的UITableView单元格中获取文本,并在用户按下单元格时将其存储在字符串中

但是,当您使用自定义单元格时,如何做到这一点?因为我的UILabel的名称是“type_label”,它已在我的CustomCell XIB的头文件中定义

所以在Xcode中我不能使用:

cell.type_label.text"
在以下功能中:

-(void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

谢谢你,丹。

在tableViewDidSelectRow中,你需要做的就是:

UITableViewCellCustomClass *customCell = (UITableViewVellCustomClass*)[tableView cellForRowAtIndexPath:indexPath];

NSString *labelText = [[customCell type_label] text];

这应该可以满足您的需要。

尝试下面的代码-您已经在ccustomcell类中创建了type_标签的IBOutlet
(文件-->新-->子类-->UITableViewCell-->将其命名为CustomCellClass)
然后实现以下代码

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath{

static NSString *cellIdentifier = @"Cell";

static BOOL nibsRegistered = NO;

if (!nibsRegistered) {

    UINib *nib = [UINib nibWithNibName:@"CustomCellClass" bundle:nil];
    [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
}

CustomCellClass *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {

    cell = [[CustomCellClass alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

cell.type_label.text = @"Rocky"; // setting custom cell label

return  cell;

}

尝试:
YourCustomCellClass*单元格=(YourCustomCellClass*)[tableView cellForRowAtIndexPath:indexPath]没有回答这个问题。@CW0007007通过实现上述代码cell.type_label.text是可能的,或者在我的示例cell.namelab.text中是。。。。在我的项目中,我已经实现了很多次……但并没有显示他如何在didSelectRow中访问这个。您只是向他展示如何设置customCell标签的文本,而不是他所要求的。。另外,你有一个静态BOOL设置为NO,然后你检查它是否为NO。它总是会为NO。。。那是多余的。