Skip to content
Permalink
Browse files

Use UIAlertController instead of UIAlertView and closure as delegate-…

…action
  • Loading branch information
bear101 committed Mar 15, 2020
1 parent 8acfd61 commit d1f08452a7631f3e9952f19f08d83e35a9d49aec
@@ -170,7 +170,6 @@ class ChannelDetailViewController :

if channel.nChannelID == 0 {
cmdid = TT_DoJoinChannel(ttInst, &channel)

}
else {
cmdid = TT_DoUpdateChannel(ttInst, &channel)
@@ -180,7 +179,9 @@ class ChannelDetailViewController :
@IBAction func joinChannelPressed(_ sender: UIButton) {

if channel.bPassword == TRUE {
let alert = UIAlertView(title: NSLocalizedString("Enter Password", comment: "Dialog message"), message: NSLocalizedString("Password", comment: "Dialog message"), delegate: self, cancelButtonTitle: NSLocalizedString("Join", comment: "Dialog message"))
let alert = UIAlertView(title: NSLocalizedString("Enter Password", comment: "Dialog message"),
message: NSLocalizedString("Password", comment: "Dialog message"), delegate: self,
cancelButtonTitle: NSLocalizedString("Join", comment: "Dialog message"))
alert.alertViewStyle = .secureTextInput
alert.textField(at: 0)?.text = self.passwdfield?.text
alert.show()
@@ -50,8 +50,7 @@ fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {

class ChannelListViewController :
UIViewController, UITableViewDataSource,
UITableViewDelegate, UIAlertViewDelegate,
MyTextMessageDelegate, TeamTalkEvent {
UITableViewDelegate, MyTextMessageDelegate, TeamTalkEvent {

// all channels on server
var channels = [INT32 : Channel]()
@@ -123,14 +122,38 @@ class ChannelListViewController :
}

func joinNewChannel(_ channel: Channel) {
if channel.bPassword != 0 {
let alertView = UIAlertView(title: NSLocalizedString("Enter Password", comment: "Dialog message"), message: NSLocalizedString("Password", comment: "Dialog message"), delegate: self, cancelButtonTitle: NSLocalizedString("Join", comment: "Dialog message"))
alertView.alertViewStyle = .secureTextInput
alertView.tag = Int(channel.nChannelID)
if let passwd = chanpasswds[channel.nChannelID] {
alertView.textField(at: 0)?.text = passwd
if channel.bPassword == TRUE {

var passwdField : UITextField?

let passwdAlert = UIAlertController(title: NSLocalizedString("Enter Password", comment: "Dialog message"),
message: NSLocalizedString("Password", comment: "Dialog message"),
preferredStyle: .alert)
passwdAlert.addTextField {(textField) in
passwdField = textField
passwdField?.autocorrectionType = .no
passwdField?.spellCheckingType = .no
passwdField?.autocapitalizationType = .none
let passwd = withUnsafePointer(to: channel) { getChannelString(PASSWORD, $0) }
passwdField?.text = String(cString: passwd!)
}
alertView.show()

passwdAlert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "Dialog message"), style: .cancel, handler: { (pAction) in
passwdAlert.dismiss(animated: true, completion: nil)
}))

passwdAlert.addAction(UIAlertAction(title: NSLocalizedString("Join", comment: "Dialog message"),
style: .default, handler: { (pAction) in

let passwd = passwdField?.text
self.chanpasswds[channel.nChannelID] = passwd
self.cmdid = TT_DoJoinChannelByID(ttInst, channel.nChannelID, passwd)
self.activeCommands[self.cmdid] = .joinCmd

passwdAlert.dismiss(animated: true, completion: nil)
}))

self.present(passwdAlert, animated: true, completion: nil)
}
else {
cmdid = TT_DoJoinChannelByID(ttInst, channel.nChannelID, "")
@@ -139,13 +162,6 @@ class ChannelListViewController :

}

func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
let passwd = (alertView.textField(at: 0)?.text)!
chanpasswds[INT32(alertView.tag)] = passwd
cmdid = TT_DoJoinChannelByID(ttInst, INT32(alertView.tag), passwd)
activeCommands[cmdid] = .joinCmd
}

func appendTextMessage(_ userid: INT32, txtmsg: MyTextMessage) {

if textmessages[userid] == nil {

0 comments on commit d1f0845

Please sign in to comment.
You can’t perform that action at this time.