UITableView - iPad - 在 UITableViewCell 类型的对象上找不到属性



我已经在 Xcode 中使用 StoryBoard(面向 iOS6)将 UITableView 原型单元添加到 iPad 应用程序的 UIView 中。

我遇到的问题是,当我尝试引用标签时,标签在我的视图控制器中无法识别。

在我的实现中,我有:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"dashboardMessage";
    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    int row = [indexPath row];

       cell.messageSender.text = [_matches valueForKey:@"from"];
}

最后一行导致错误:在 UITableViewCell 类型的对象上找不到属性"messageSender"

在单元格的头文件中,我有:

@interface DashboardMessageCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *messageSender;
@property (strong, nonatomic) IBOutlet UILabel *messageDescr;

并将头文件导入到视图控制器中。

我不知道是什么导致了这个问题,任何帮助将不胜感激。

谢谢。

单元格的类型必须是 DashboardMessageCell 您的代码可能是这样的:

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"dashboardMessage";
DashboardMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
      cell = [[DashboardMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
   }
   int row = [indexPath row];
   cell.messageSender.text = [_matches valueForKey:@"from"];
}

我不敢尝试此代码我希望它能帮助你

最新更新