代码之家  ›  专栏  ›  技术社区  ›  Andreas Prang

从自定义UITableViewCell获取textField.text

  •  2
  • Andreas Prang  · 技术社区  · 16 年前

    我写了一个特别的UITableViewCell。现在我需要把文本从

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomCell *custumCell = [tableView cellForRowAtIndexPath:indexPath];
        //warning: incompatible Objective-C types initializing 'struct UITableViewCell *', expected 'struct CustomCell *'
    
    NSString *title = [custumCell cellTitle].text;
    [self setArticleReaded:title];
    [title release];
    

    }

    #import <UIKit/UIKit.h>
    
    
    @interface CustomCell : UITableViewCell {
        IBOutlet UILabel *cellTitle;
        IBOutlet UILabel *cellSubTitle;
        IBOutlet UILabel *cellPubDate;
    }
    
    @property (nonatomic, retain) IBOutlet UILabel *cellTitle;
    @property (nonatomic, retain) IBOutlet UILabel *cellSubTitle;
    @property (nonatomic, retain) IBOutlet UILabel *cellPubDate;
    
    @end
    

    我希望有人知道解决办法。

    3 回复  |  直到 16 年前
        1
  •  8
  •   Alex Reynolds    16 年前

    投出它:

    CustomCell *custumCell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
    

    这样您就可以访问单元格的属性。

        2
  •  1
  •   Ole Begemann    16 年前

    应转换为CustomCell类型:

    CustomCell *custumCell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
    
        3
  •  0
  •   Michael Kessler    16 年前

    我认为调用cellforrowatinexpath没有任何意义,它用数据源(例如NSArray)构建单元格并用文本填充cellText。然后访问cellText属性。