在类型的对象上找不到 tableView [英] tableView not found on object of type

查看:38
本文介绍了在类型的对象上找不到 tableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 FirstViewController 的类,它是 UIViewController 的子类,并且我在该类中有一个 UITableView.当按下一行时,我需要从这个类转换到一个新的 UIViewController 子类(使用 segues).

I have a class named FirstViewController which is a subclass of UIViewController and I have a UITableView in the class. I need to transition from this class to a new UIViewController subclass (using segues) when a row is pressed.

我使用代码将 FirstViewController 设为 UITableViewDelegate 和 UITableViewDataSource -

I have made the FirstViewController the UITableViewDelegate and UITableViewDataSource using the code -

@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

我在这行代码上遇到错误 -

I am getting an error on this line of code -

NSIndexPath *path = [self.tableView indexPathForSelectedRow];

如何解决这个问题,因为 tableView 是在 UITableViewController 而不是 UIViewController 类中找到的?

How do I fix this problem since the tableView is found in UITableViewController and not in UIViewController class ?

编辑 -

这是与我的表格视图相关的代码 -

Here's the code related to my table view -

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [sarray count];
}

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

    static NSString *cellId = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];

    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }

    NSString *text = [sarray objectAtIndex:[indexPath row]];
    cell.textLabel.text = text;
    return cell;
}

推荐答案

你可以简单地将 tableView 声明为一个属性:

You can simply declare tableView as a property:

@property(nonatomic, strong) IBOutlet UITableView *tableView;

这篇关于在类型的对象上找不到 tableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆