我是xcode的新手。我正在尝试在ibeacon上做一个小项目。现在的问题是我在viewcontroller中包含了一个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 =@"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 :(得分:0)
您需要通知tableview数据已更改 - 请致电
[tableView reloadData]
在您的didRangeBeacons
方法中 - 这将使其再次呼叫numberOfRowsInSection
答案 1 :(得分:0)
收到通知并更新数据源后,您必须拨打reloadData
上的UITableView
方法
[tableView reloadData];
答案 2 :(得分:0)
我没有找到UITableView
.h
<{1>}文件中的
@property (strong, nonatomic) UITableView *objTableView;
然后
在.m
@synthesize objTableView;