tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 [英] tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

查看:32
本文介绍了tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.我收到此错误:

I have a weird problem. I get this error:

 -[FourSquareCheckInViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7aecc0
2012-09-14 19:18:39.039 [5869:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FourSquareCheckInViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7aecc0'
*** First throw call stack:
(0x3545e88f 0x37805259 0x35461a9b 0x35460a83 0x353bb650 0x32ee3693 0x32ee49ed 0x32ee493f 0x32ee451b 0x32ef17df 0x32ef16af 0x32e95f37 0x353bd1fb 0x3228daa5 0x3228d6bd 0x32291843 0x3229157f 0x322894b9 0x35432b1b 0x35430d57 0x354310b1 0x353b44a5 0x353b436d 0x37050439 0x32ec0cd5 0xb7ebb 0xb7e60)
terminate called throwing an exception(lldb) 

好的,所以我确保将 ViewController 设置为 dataSource 和 Delegate.我已将 UITableViewDelegate 和 UITableViewDataSource 添加到 <> 东西中.

Ok so I have made sure that the ViewController is set as the dataSource and the Delegate. I have added the UITableViewDelegate and UITableViewDataSource to the <> thingies.

我在 viewDidLoad 方法中设置了 tableView.delegate = self 和 tableView.dataSource = self.

I have set tableView.delegate = self and tableView.dataSource = self in my viewDidLoad method.

这是我对 viewDidLoad 和 viewDidAppear 方法的实现:

Here is my implementation of the viewDidLoad and viewDidAppear methods:

- (void)viewWillAppear:(BOOL)animated{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; // 1km
    [locationManager startUpdatingLocation];
    locationLat = [locationManager location].coordinate.latitude;
    locationLng = [locationManager location].coordinate.longitude;
    [locationManager stopUpdatingLocation];

    // 1
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = locationLat;
    zoomLocation.longitude= locationLng;
    // 2
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
    // 3
    MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];                
    // 4
    [_mapView setRegion:adjustedRegion animated:YES]; 
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _tableView.delegate = self;
    _tableView.dataSource = self;

    // Do any additional setup after loading the view.
    // 1
    MKCoordinateRegion mapRegion = [_mapView region];
    CLLocationCoordinate2D centerLocation = mapRegion.center;

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; // 1km
    [locationManager startUpdatingLocation];
    locationLat = [locationManager location].coordinate.latitude;
    locationLng = [locationManager location].coordinate.longitude;
    [locationManager stopUpdatingLocation];

}

这是我的 numberOfRowsInSection 方法体:

Here is my method body for numberOfRowsInSection:

- (NSInteger)numberOfRowsInSection:(NSInteger)section{
    return 5;
}

这是我的视图控制器头文件:

Here is my header file for the view controller:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

#define METERS_PER_MILE 1609.344

@interface FourSquareCheckInViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate, MKMapViewDelegate>{

}


@property (weak, nonatomic) IBOutlet MKMapView *_mapView;

- (NSInteger)numberOfRowsInSection:(NSInteger)section;
@property (weak, nonatomic) IBOutlet UITableView *_tableView;



@end

这是一个屏幕截图,显示了我的 tableView 是如何连接的:

Here is a screenshot showing how my tableView is hooked up:

推荐答案

阅读错误消息告诉您的内容!

Read what the error message is telling you!

您已经实施了 numberOfRowsInSection:.所以呢?那是错误的方法.这是无关紧要的.它永远不会被调用.

You have implemented numberOfRowsInSection:. So what? That's the wrong method. It is irrelevant. It will never be called.

您需要实现的方法称为tableView:numberOfRowsInSection:.那是完全不同的.

The method you need to implement is called tableView:numberOfRowsInSection:. That's completely different.

这篇关于tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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