如果我制作如下属性:
@property(nonatomic, strong) NSString *RSSIvalue;
然后我合成它:
@synthesize RSSIvalue;
我可以将其定义为一种方法:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
RSSIvalue = [NSString stringWithFormat:@"%ld", (long)RSSI.integerValue];
}
然后使用我在其他方法中定义的值:
- (IBAction)setNValueAt1meter:(id)sender
{
self.nValue1m.text = RSSIvalue;
}
答案 0 :(得分:2)
是的,只要您获得正确的订单。
然而,在我看来,RSSIvalue
应该存储为您在演示期间格式化的数字:
@property(nonatomic, strong) NSNumber *RSSIvalue;
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
self.RSSIvalue = RSSI;
}
- (IBAction)setNValueAt1meter:(id)sender
{
self.nValue1m.text = [NSString stringWithFormat:@"%@", self.RSSIvalue];
// same as this, only more expensive:
// self.nValue1m.text = [self.RSSIvalue description];
}
请注意self.RSSIvalue
的使用。您甚至可以将其设为long
,这更简单。