登录后显示另一个viewController但出错

时间:2014-05-12 19:26:38

标签: ios objective-c uitableview

我已经完成了2个教程和100%正确的单独工作,但是当它们组合在一起时会出现以下错误。

  

2014-05-12 14:49:12.638 app-ios [13988:60b] PostData:nick = demo& pass_field = demo
  2014-05-12 14:49:12.991 app-ios [13988:60b]回复代码:201
  2014-05-12 14:49:12.992 app-ios [13988:60b]回复==> {" nick":" demo"," avatar":" img / noavatar.jpg"," name": "演示用户","成功":" 1"," id":9}
  2014-05-12 14:49:12.993 app-ios [13988:60b]成功:1
  2014-05-12 14:49:12.994 app-ios [13988:60b]登录成功
  2014-05-12 14:49:13.017 app-ios [13988:60b] - [UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x14edfc30
  2014-05-12 14:49:13.018 app-ios [13988:60b] ***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [UIViewController tableView:numberOfRowsInSection:] :无法识别的选择器发送到实例0x14edfc30'
  ***首先抛出调用堆栈:
  (0x30c62f0b 0x3b3f9ce7 0x30c66837 0x30c65137 0x30bb4098 0x33566873 0x33568b71 0x33568ac5 0x335686bf 0x3356bbb3 0x33492305 0x3310e31b 0x33109b3f 0x334a74a1 0x335bf29d 0x335bf0e9 0x335be5a1 0x335be41f 0x335be2f7 0x334a40d5 0x335c1ee5 0x335c11cb 0x334acce3 0x3357c281 0x3357a5f9 0x3375d507 0x8ffbb 0x334c76c7 0x334c7663 0x334c7633 0x334b2d7b 0x334c707b 0x334c6d4d 0x334c1ca7 0x33496e75 0x33495541 0x30c2dfef 0x30c2d4b7 0x30c2bca7 0x30b96769 0x30b9654b 0x35b036d3 0x334f5891 0x90c2d 0x3b8f7ab7)
  libc ++ abi.dylib:以NSException类型的未捕获异常终止

用户登录后我尝试做的是显示带有一些数据的tableView。

这是SearchViewController.m

    //  SearchViewController.m

    #import "SearchViewController.h"

    @interface SearchViewController ()

    @end

    @implementation SearchViewController {
        NSArray *users;
    }

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        users = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast",
                   @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and CheesePanini", nil];
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [users count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *simpleTableIdentifier = @"SimpleTableCell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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

        cell.textLabel.text = [users objectAtIndex:indexPath.row];
        cell.imageView.image = [UIImage imageNamed:@"avatar1.jpg"];

        return cell;
    }

    /*
    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    @end

enter image description here

1 个答案:

答案 0 :(得分:0)

异常消息告诉您有一个U IViewController被指定为您的表数据源和没有实现这些协议的委托。您的代码表明您的委托/ tableview类是SearchViewController。您需要确保表视图中的delegatedataSource出口引用SearchViewController的实例。

屏幕截图中显示的对象类型是什么?