0
내 iBeacon 응용 프로그램의 코드를 xib 형식에서 스토리 보드로 변환하는 데 문제가 있습니다. 표 셀에는 아무것도 표시되지 않습니다. 모든 도움을 주시면 감사하겠습니다!xib에서 스토리 보드로 변환
#import "RangingViewController.h"
#import "Default.h"
@implementation RangingViewController
{
NSMutableDictionary *_beacons;
CLLocationManager *_locationManager;
NSMutableArray *_rangedRegions;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if(self)
{
_beacons = [[NSMutableDictionary alloc] init];
// This location manager will be used to demonstrate how to range beacons.
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
// CoreLocation will call this delegate method at 1 Hz with updated range information.
// Beacons will be categorized and displayed by proximity.
[_beacons removeAllObjects];
NSArray *unknownBeacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"proximity = %d", CLProximityUnknown]];
if([unknownBeacons count])
[_beacons setObject:unknownBeacons forKey:[NSNumber numberWithInt:CLProximityUnknown]];
NSArray *immediateBeacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"proximity = %d", CLProximityImmediate]];
if([immediateBeacons count])
[_beacons setObject:immediateBeacons forKey:[NSNumber numberWithInt:CLProximityImmediate]];
NSArray *nearBeacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"proximity = %d", CLProximityNear]];
if([nearBeacons count])
[_beacons setObject:nearBeacons forKey:[NSNumber numberWithInt:CLProximityNear]];
NSArray *farBeacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"proximity = %d", CLProximityFar]];
if([farBeacons count])
[_beacons setObject:farBeacons forKey:[NSNumber numberWithInt:CLProximityFar]];
[self.rangeTable reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
// Start ranging when the view appears.
[_rangedRegions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CLBeaconRegion *region = obj;
[_locationManager startRangingBeaconsInRegion:region];
}];
}
- (void)viewDidDisappear:(BOOL)animated
{
// Stop ranging when the view goes away.
[_rangedRegions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CLBeaconRegion *region = obj;
[_locationManager stopRangingBeaconsInRegion:region];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Ranging";
// Populate the regions we will range once.
_rangedRegions = [NSMutableArray array];
[[Default sharedDefaults].supportedProximityUUIDs enumerateObjectsUsingBlock:^(id uuidObj, NSUInteger uuidIdx, BOOL *uuidStop) {
NSUUID *uuid = (NSUUID *)uuidObj;
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:[uuid UUIDString]];
[_rangedRegions addObject:region];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)rangeTable
{
return _beacons.count;
}
- (NSInteger)tableView:(UITableView *)rangeTable numberOfRowsInSection:(NSInteger)section
{
NSArray *sectionValues = [_beacons allValues];
return [[sectionValues objectAtIndex:section] count];
}
- (NSString *)tableView:(UITableView *)rangeTable titleForHeaderInSection:(NSInteger)section
{
NSString *title = nil;
NSArray *sectionKeys = [_beacons allKeys];
// The table view will display beacons by proximity.
NSNumber *sectionKey = [sectionKeys objectAtIndex:section];
switch([sectionKey integerValue])
{
case CLProximityImmediate:
title = @"Immediate";
break;
case CLProximityNear:
title = @"Near";
break;
case CLProximityFar:
title = @"Far";
break;
default:
title = @"Unknown";
break;
}
return title;
}
- (UITableViewCell *)tableView:(UITableView *)rangeTable cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
_rangeCell = [rangeTable dequeueReusableCellWithIdentifier:identifier];
if (_rangeCell == nil)
{
_rangeCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
_rangeCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Display the UUID, major, minor and accuracy for each beacon.
NSNumber *sectionKey = [[_beacons allKeys] objectAtIndex:indexPath.section];
CLBeacon *beacon = [[_beacons objectForKey:sectionKey] objectAtIndex:indexPath.row];
_rangeCell.textLabel.text = [beacon.proximityUUID UUIDString];
_rangeCell.detailTextLabel.text = [NSString stringWithFormat:@"Major: %@, Minor: %@, Acc: %.2fm", beacon.major, beacon.minor, beacon.accuracy];
return _rangeCell;
}
@end
_rangeCell로 TableViewCell을 선언하고 rangeView로 TableView를 선언했습니다. 스토리 보드 에서
스토리 보드에서 셀 식별자를 "셀"로 설정 했습니까? 한 번 확인하십시오. – cjd
IBOutlet 속성을 스토리 보드의 해당 부분에 연결 했습니까? –
나는 그들을 연결했지만 여전히 작동하지 않습니다. – user3161723