Tôi gặp vấn đề lạ. Tôi gặp lỗi này:tableView: numberOfRowsInSection:]: bộ chọn không được nhận dạng được gửi đến dụ
-[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)
Ok vì vậy tôi đã đảm bảo rằng ViewController được đặt làm dataSource và Ủy quyền. Tôi đã thêm UITableViewDelegate và UITableViewDataSource vào các điều khoản <>.
Tôi đã đặt tableView.delegate = self và tableView.dataSource = self trong phương thức viewDidLoad của tôi.
Đây là triển khai thực hiện của tôi về phương pháp viewDidLoad và 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];
}
Đây là cơ thể phương pháp của tôi cho numberOfRowsInSection:
- (NSInteger)numberOfRowsInSection:(NSInteger)section{
return 5;
}
Đây là tập tin header của tôi cho bộ điều khiển xem:
#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
Dưới đây là ảnh chụp màn hình hiển thị cách xem bảng của tôi được ghép nối:
Tôi có thể có một số ví dụ mã của phương pháp này không? Tôi không thể tìm thấy nó. – jimbob
http://developer.apple.com/library/ios/documentation/userexperience/conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW5 – matt
tài liệu: http: // nhà phát triển .apple.com/library/ios/# documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html – matt