2014-01-21 2 views
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를 선언했습니다. 스토리 보드 에서

+1

스토리 보드에서 셀 식별자를 "셀"로 설정 했습니까? 한 번 확인하십시오. – cjd

+0

IBOutlet 속성을 스토리 보드의 해당 부분에 연결 했습니까? –

+0

나는 그들을 연결했지만 여전히 작동하지 않습니다. – user3161723

답변

0

는 서브 클래스없이 아래에있는 내 코드 -USE 셀 식별자 - 설정 객체 와 -Remove 모든 후크 링크를 프로토 타입 셀을 만들고 나에게 문제가 지속되면 알려 - 첫째 :

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

// Configure the cell... 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

    // Set the indexes according to your UIControls Listing  
    UILabel *lblMainText = (UILabel *)[cell.contentView.subviews objectAtIndex:0]; 
    UILabel *lblDetailText = (UILabel *)[cell.contentView.subviews objectAtIndex:3]; 
    UILabel *lblDetailText2 = (UILabel *)[cell.contentView.subviews objectAtIndex:1]; 
    UILabel *lblDetailText3 = (UILabel *)[cell.contentView.subviews objectAtIndex:2]; 
    UIButton *btnFavourite = (UIButton *)[cell.contentView.subviews objectAtIndex:6]; 
    UIButton *btnMore = (UIButton *)[cell.contentView.subviews objectAtIndex:4]; 
//cell.backgroundColor = [UIColor clearColor]; 
lblMainText.text = [NSString stringWithFormat:@"%@",@"someValue"]; 
    lblDetailText.text= [NSString stringWithFormat:@"%@",@"someValue"]; 
    lblDetailText2.text= [NSString stringWithFormat:@"%@",@"someValue"]; 
    lblDetailText3.text= [NSString stringWithFormat:@"Marks",@"someValue"]; 
    btnFavourite.tag = indexPath.row; 
    [btnFavourite addTarget:self 
         action:@selector(callMethod:) forControlEvents:UIControlEventTouchUpInside]; 
btnFavourite.tag = indexPath.row; 
return cell; 
    } 
관련 문제