IOS 10 Problems
Some Notes on Problems I've Encountered
iOS 10: “"[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
This fixed it - In your Xcode UI:
- Click on your active scheme name right next to the Stop button
- Click on Edit Scheme....
- in Run (Debug) select the Arguments tab
- in Environment Variables click '+'
- add the variable: OS_ACTIVITY_MODE with Value: disable
How do I Add an ActivityIndicator?
I found this a useful reference - http://stackoverflow.com/questions/2638120/can-i-change-the-size-of-uiactivityindicator
Added the following to my (TableView)ViewController to get an ActivityIndicator which data was requested (over the Internet) and loaded into the TableView
var activityIndicator: UIActivityIndicatorView?
private var data = [Data]()
{
didSet {
tableView.reloadData()
activityIndicator?.stopAnimating()
}
}
...
func startActivityIndicator(_ scale: CGFloat) -> UIActivityIndicatorView?
{
let ai = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
ai.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
ai.scale(factor: 2.0)
// let transform: CGAffineTransform = CGAffineTransform(scaleX: scale, y: scale)
// ai.transform = transform
ai.center = self.view.center
ai.startAnimating()
self.view.addSubview(ai)
return ai
}
...
private func loadData()
{
activityIndicator = startActivityIndicator(2.0)
let request = DataRequest()
request.fetchData { [weak self] newData in
self?.data = newData
}
}
How do I Scale It?
Nice solution from StackOverflow link was to add an extension to the ViewController source file:
extension UIActivityIndicatorView {
func scale(factor: CGFloat) {
guard factor > 0.0 else { return }
transform = CGAffineTransform(scaleX: factor, y: factor)
}
}
Waltzing with the Software Keyboard
I have a TextField in a Navigation Bar which I want to use to enter some search text. When I give focus to the TextField the keyboard appears. I am still working on getting this to close the keyboard once it is shown:
A Google search turned up this - http://stackoverflow.com/questions/18755410/how-to-dismiss-keyboard-ios-programmatically
@IBOutlet weak var searchTextField: UITextField!
...
override func viewDidLoad()
{
super.viewDidLoad()
...
let tap = UITapGestureRecognizer(target: self, action: #selector(onTouchGesture))
self.view.addGestureRecognizer(tap)
}
func textFieldShouldReturn(textField: UITextField) -> Bool
{
if (textField.returnKeyType == UIReturnKeyType.default)
{
if let next = textField.superview?.viewWithTag(textField.tag+1) as? UITextField
{
next.becomeFirstResponder()
return false
}
}
textField.resignFirstResponder()
return false
}
func onTouchGesture()
{
searchTextField?.resignFirstResponder()
self.view.endEditing(true)
}
The Tap recognizer works. But I haven't managed to do a resignFirstResponder() on the TextField.
Added an IBOutlet to reference the TextField and used this to send a resignFirstResponder() message when I tap outside the keyboard. This much works but isn't the final solution.
Sending an endEditing message to the searchTextField works and seems cleaner:
func onTouchGesture()
{
// searchTextField?.resignFirstResponder()
searchTextField?.endEditing(true)
}
These look useful: