'BLE Peripheral disconnects when navigating to different ViewController
I am working on BLE iOS (Swift) application which has multiple ViewControllers. The main ViewController has a button which navigates to TableViewController which has detected BLE devices to connect with. But when I return back to main or another view the peripheral device disconnects. I tried to pass peripheral from TableViewController to main ViewController but still, it disconnects.
MainViewController:
var bleManager: BLEManager!
var peripheral: CBPeripheral!
override func viewDidLoad() {
bleManager = BLEManager()
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
if let peripheral = self.peripheral {
do {
print("Value from display = \(peripheral.state)")
}
}
}
func setPeripheral(sent: CBPeripheral) {
self.peripheral = sent
}
@IBAction func manageDevice(sender: UIButton)
{
// 1. Instantiate TableViewController
let tableViewController = self.storyboard?.instantiateViewController(withIdentifier: "TableViewController") as! TableViewController
// 2. Set self as a value to delegate
tableViewController.delegate = self
// 3. Push SecondViewController
self.navigationController?.pushViewController(tableViewController, animated: true)
}
Solution 1:[1]
- You need to supply Axis=1 to apply the function to each row.
2.
xin your function would be a row (not a cell). - You can convert
x, the row, to a list. - Count how many times each value is in the list, and multiply it by its value.
- Sum, and output the result.
Solution 2:[2]
Make your life easy by choosing Python over pandas.
score_dict = {'Green': 1, 'Yellow': 0.5, 'Red': 0}
df = pd.DataFrame(data)
df["total_score"] = 0.0
for index, row in df.iterrows():
df.at[index, "total_score"] = score_dict[row["Index1"]] + score_dict[row["Index2"]]
print(df)
Solution 3:[3]
Came up with this solution.
scores = []
for index in range(len(df.index)):
scoreTotal = 0
for column in df.columns:
color = df[column][index]
scoreTotal += color_to_score(color)
scores.append(scoreTotal)
df["Score"] = scores
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | OnY |
| Solution 2 | shivankgtm |
| Solution 3 | tiagob01 |
