iphone - 在 subview 中使用 UITableView 时无法识别的选择器

标签 iphone uitableview

我正在构建一个使用 TabBarController 来显示其他几个 View 的应用程序。在这些 View 之一中,我使用导航 Controller 来导航一些表格数据。当用户单击此选项卡时,我会加载 NavigationController,而导航 Controller 又会加载我正在使用的 TableView。问题是我在加载 TableView Controller 时收到以下错误:

-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6b37b10

我到处都读到这种类型的错误通常来自于 IB 中的错误连接或者 View Controller 中的类不正确。这是我的代码和 IB 的屏幕截图,以帮助我调试这个问题。

提前致谢!

我收到的错误

alt text IB中TableView的连接

alt text 文件所有者类 alt text 我的界面文件

@interface FAQListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {

    // Dictionary that will hold the FAQ Key/Values
    NSMutableArray  *arrFAQData;

}

实现

@implementation FAQListViewController

// Implementation for UITableView numberOfRowsInSection protocol
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [arrFAQData count];

}

// Implementation for UITableView cellForRowAtIndexPath protocol
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // See if we have any cells available for reuse
    UITableViewCell *objCell = [tableView dequeueReusableCellWithIdentifier:@"FAQCell"];
    if (objCell == nil) {

        // No reusable cell exists, so let's create a new one
        objCell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"FAQCell"];

    }

    // Give it data
    NSDictionary *objRow = [arrFAQData objectAtIndex: [indexPath row]];
    objCell.textLabel.text = [objRow valueForKey:@"Title"];

    // Return the created cell
    return objCell;


}

// Selection Event Handler
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Get the value for the selected key
    NSDictionary *dictRow = [arrFAQData objectAtIndex:[indexPath row]];
    NSString *strURL = [dictRow valueForKey: @"URL"];

    // Alert result
    UIAlertView *objAlert;
    objAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message: strURL delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 

    // Release created objects
    [objAlert show];
    [objAlert release];

    // Deselect row
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
- (void)viewDidLoad {

    // Pull in FAQ from Plist
    NSString *strFAQPlist = [[NSBundle mainBundle] pathForResource:@"FAQData" ofType:@"plist"];
    arrFAQData = [[NSMutableArray alloc] initWithContentsOfFile: strFAQPlist];


    [super viewDidLoad];
}

- (void)dealloc {

    [arrFAQData release];


    [super dealloc];
}

最佳答案

首先,这是一个结构良好的问题,我希望每个人都发布屏幕截图和完整的源代码。 :-)

看起来消息正在发送到通用 UIViewController,而不是 FAQListViewController。这告诉我,也许当您实例化 FAQListViewController 时,您正在创建 UIViewController 的实例?

要实例化常见问题解答列表,您应该使用类似以下内容的内容:

[[FAQListViewController alloc] initWithNibName: @"FAQViewController"包: nil];

如果您像这样实例化它,则可能会出现错误:

[[UIViewController alloc] initWithNibName: @"FAQViewController"包: nil];

关于iphone - 在 subview 中使用 UITableView 时无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3603268/

相关文章:

iphone - 自动旋转动态 UIViewcontroller

iphone - 适用于 iOS 的线性规划库

iphone - 如何将背景图像放入 iPhone 中的文本字段和 TextView ?

ios - MPMediaItemArtwork 和 UITableView

macos - OS X 中是否有任何 iOS UITableView 模拟?

ios - 滚动 tableView ios swift 的末尾

iphone - 如何使用 xib 文件中的任何 subview (在 xib 中创建)的多个副本

ios - 从 UITableViewCell 将 UIImageView 扩展到全屏

ios - UITableView 显示 'phantom cell'

iphone - 在自定义 MKOverlay 上绘图