当我想从valise,表视图控制器(SelectedCity),应用程序崩溃和错误中创建数据时:Thread1:EXC_BAD_ACCESS(代码= 1,地址0x ...)
错误是行 For i = 0 To 10
Try
'System.IO.File.Delete(sFileName)
'My.Computer.FileSystem.DeleteFile(sFileName, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
My.Computer.FileSystem.DeleteFile(sFileName)
Exit For
Catch ex As Exception
If i = 10 Then
invioMailTest(ex.ToString)
End If
Threading.Thread.Sleep(1000)
End Try
Next
varibale tit没问题,我认为问题出在UIlabel(labelcity)
AircraftSearch
labelcity!.text = tit
SelectedCity视图
class AircraftSearch: UIViewController ,SendbackDelegate{
@IBOutlet weak var Mabda: UIButton!
@IBOutlet weak var maghsad: UIButton!
@IBOutlet weak var labelcity: UILabel!
var Airurl = NSURL()
var ScrOrDstArray = [MabdaAndMaghsad]()
var origin = [String]() // save mabda
var purpose = [String]() // save maghsad
var sendDataToTableview = [String]()
var tit = String()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
GetPassCity()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func selectMabda(sender: AnyObject) {
sendDataToTableview = origin
performSegueWithIdentifier("SelectedCellSegue", sender: sender)
}
@IBAction func selectMaghsad(sender: AnyObject) {
sendDataToTableview = purpose
print(sendDataToTableview)
performSegueWithIdentifier("SelectedCellSegue", sender: sender)
}
func originAndpurpose() {
let dataCity = ScrOrDstArray
for i in dataCity{
if i.SrcOrDst == true{
origin.append(i.Name)
}else{
purpose.append(i.Name)
}
}
}
func sendNameToPreviousVC(SelectCity: String) {
print("\(tit) selected ") //return data
tit = SelectCity
labelcity!.text = tit
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "SelectedCellSegue" {
if let VC = segue.destinationViewController as? SelectedCity {
VC.toTake = sendDataToTableview
VC.delegate = self
}
}
}
}
答案 0 :(得分:0)
而不是
尝试:
@IBOutlet weak var labelcity: UILabel? = UILabel()
答案 1 :(得分:0)
考虑在属性声明中删除弱关键字。使用此关键字可以防止刚创建的UILabel对象被保留,因此该对象会立即释放。
var labelcity: UILabel? = UILabel()
或另一种选择是将对象实例化移动到viewDidLoad方法:
var labelcity: UILabel!
...
override func viewDidLoad() {
super.viewDidLoad()
let label = UILabel()
//you code for subview adding into view controller's view
labelcity = label
GetPassCity()
}
答案 2 :(得分:0)
我解决了这个问题:
override func viewDidLoad() {
super.viewDidLoad()
labelcity.text = tit
GetPassCity()
}
func sendNameToPreviousVC(SelectCity: String) {
tit = SelectCity
}