안녕하세요. 앱이 시작될 때 LoginAlert가 표시되는 데 문제가 있습니다. 앱이 성공적으로 빌드되지만 알림보기가 표시되지 않습니다. 내가 뭘 놓치고 있니?UIAlertView가 나타나지 않습니다.
모든 통찰력을 미리 감사드립니다!
// TimelineTableViewController.swift
import UIKit
class TimelineTableViewController: UITableViewController {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidAppear(animated: Bool) {
if ((PFUser.currentUser()) != nil){
var loginAlert:UIAlertController = UIAlertController(title: "Sign Up/Login",message: "Please Sign up or Login",
preferredStyle: UIAlertControllerStyle.Alert)
loginAlert.addTextFieldWithConfigurationHandler({
textfield in
textfield.placeholder = "Your username"
})
loginAlert.addTextFieldWithConfigurationHandler({
textfield in
textfield.placeholder = "Your password"
textfield.secureTextEntry = true
})
loginAlert.addAction(UIAlertAction(title: "Login", style: UIAlertActionStyle.Default, handler:{
alertAction in
let textFields:NSArray = loginAlert.textFields! as NSArray
let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
PFUser.logInWithUsernameInBackground(usernameTextfield.text, password: passwordTextfield.text){
(user:PFUser!, error:NSError!)->Void in
if ((user) != nil){
println("Login successful")
}else{
println("Login Failed")
}
}
}))
loginAlert.addAction(UIAlertAction(title: "Sign Up", style: UIAlertActionStyle.Default, handler:{
alertAction in
let textFields:NSArray = loginAlert.textFields! as NSArray
let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
var poster:PFUser = PFUser()
poster.username = usernameTextfield.text
poster.password = passwordTextfield.text
poster.signUpInBackgroundWithBlock{
(success:Bool!, error:NSError!)->Void in
if !(error != nil){
println("Sign Up Successful")
}else{
let errorString = error.userInfo!["error"] as String
println(errorString)
}
}
}))
self.presentViewController(loginAlert, animated: true, completion: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
가 어떻게 loginAlert에 대한 클래스를 만들 것인가? (미안하지만 초급인데 ...) – user3708224
이것은 문제가되지 않습니다. presentViewController의 retainCount가 증가 할 것이므로 로컬 변수와 상관 없습니다. – iMemon