ios - TableView :numberOfRowsInSection:]: unrecognized selector sent to instance

标签 ios xcode uitableview delegates

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

 -[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 设置为数据源和委托(delegate)。我已将 UITableViewDelegate 和 UITableViewDataSource 添加到 <> thingies。

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

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

- (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 方法体:

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

这是我的 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 是如何连接的屏幕截图:

enter image description here

最佳答案

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

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

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

关于ios - TableView :numberOfRowsInSection:]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12431013/

相关文章:

iphone - Storyboard 中封面垂直过渡的对面

ios - 如何从 ios 将订单 ID 发送到 paypal

ios - 当用户点击或滚动 UITableView 时如何取消功能?

ios - UITableView 滚动到不同设备上的行

ios - 我怎样才能圆容器 TableView 的角落?

ios - 如何使用 RxSwift 从返回 Observable 的服务中获取值

ios - Core Text - 字形高度

ios - 无法将我的应用程序上传到应用程序商店

ios - iBeacon 接收器无法识别传输的信号

ios - 从 Nsnumber 转换为数据以将 rssi 发送到蓝牙模块 IOS swift 4