2014-04-14 5 views
0

xcode를 처음 사용했습니다. ibeacon에서 작은 프로젝트를하려고합니다. 이제 문제는 내 viewcontroller (tabview 컨트롤러를 사용하여 오전) tableview 포함되어 있습니다. 내가 원하는 주요 값과 일치하는 신호를 찾으면 테이블을 업데이트하고 싶었습니다.내 테이블의 값이 표시되지 않습니다.

내 코드를 사용하면 지역에 들어서 신호를 감지하고 알림을 받았습니다. 그러나 내가 그 알림을 열면 내가 설정 한 배열로 테이블이 업데이트되지 않습니다.

#import "SBSFirstViewController.h" 


@interface SBSFirstViewController() 


@property (strong, nonatomic) CLBeaconRegion *beaconRegion; 
@property (strong, nonatomic) CLLocationManager *locationManager; 
@property BOOL checkDidEnterBusStop; 
@property (strong, nonatomic) CLBeacon *selectedBeacon; 

@end 

@implementation SBSFirstViewController 


NSArray *buses; 
BOOL checkDidEnterBusStop = NO; 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 

if(checkDidEnterBusStop == YES){ 
    return [buses count]; 
} 
return 0; 

} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath{ 

static NSString *tableIdentifier [email protected]"BusCell"; 


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier]; 

if(cell==nil){ 

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier]; 

} 



cell.textLabel.text = [buses objectAtIndex:indexPath.row]; 



return cell; 



} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

buses = [NSArray arrayWithObjects:@"3", @"83", @"62", nil]; 

self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.delegate = self; 

[self initRegion]; 

[self.locationManager startMonitoringForRegion:_beaconRegion]; 
_beaconRegion.notifyOnEntry = YES; 

NSLog(@"start monitoring"); 




} 



-(void)initRegion 
{ 
NSUUID *demoBusStopUUID = [[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"]; 

self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:demoBusStopUUID major:23118 minor:37538 identifier:@"estimoteAtBusStop"]; 



} 




-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{ 

[self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; 
NSLog(@"entered region"); 



} 

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{ 

[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion]; 
} 



-(void) locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { 


checkDidEnterBusStop=YES; 


UILocalNotification *notification = [[UILocalNotification alloc]init]; 
notification.alertBody = @"You have reached the bus stop"; 
notification.soundName = UILocalNotificationDefaultSoundName; 

[[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 

} 





- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 





@end 

누군가 내 실수를 지적함으로써 나를 도울 수 있습니까? 감사합니다

답변

0

당신은 데이터가 변경된 것을있는 tableview를 통지 할 필요가 - 당신의 didRangeBeacons 방법에

[tableView reloadData] 

를 호출 - 이것은 당신이 통지를받은 후이 numberOfRowsInSection 다시

+0

덕분에 .m 파일 다음

@synthesize objTableView; 

에서 .h 파일

@property (strong, nonatomic) UITableView *objTableView; 

에서 UITableView

의 요법. 이것은 viewcontroller의 tableview입니다. 나는 테이블 뷰 재로드 데이터를 호출 할 수 있도록 .h 파일로 iboutlet을 생성해야한다. 내가 맞습니까? – Ronny

+0

예, 테이블보기에서 메소드를 호출 할 수있는 방법이 필요합니다. – Paulw11

+0

감사합니다. – Ronny

0

전화를 얻고 업데이트됩니다 데이터 소스는 내가 어떤 OBJ를 찾지 않았다 UITableView

[tableView reloadData]; 
0

reloadData 메서드를 호출해야합니다 빠른 회신 ViewDidLoadMethod

if(!objTableView) 
objTableView=[[objTableView alloc]initWithFrame:CGRectMake(10, 0, 300, 300) 
              style:UITableViewStylePlain]; 
         objTableView.delegate=self; 
         objTableView.dataSource=self; 
         [self.view addSubview:objTableView]; 
관련 문제