wendyabrantes / WATokenFieldView

TokenFieldView is used to search and and tag in a text view
MIT License
36 stars 2 forks source link

How to set WATokenFieldViewDelegate in swift project #1

Closed Sasikumariosdeveloper closed 8 years ago

Sasikumariosdeveloper commented 8 years ago

Hai,

Am using WATokenFieldView obj c file into swift project through bridging header.h. when i select the WATokenFieldView the keyboard will appears. But when i click the close(x) button in keyboard delegate method did not called. please give any solutions or if am doing anything means correct me please.

Thanks in Advance.

wendyabrantes commented 8 years ago

Hi,

Have you set the delegate for the tokenFieldView ? _tokenFieldView.delegate = self;

Cheers

Sasikumariosdeveloper commented 8 years ago

Hai,

am using this library file into my swift project. so i could add header files i bridging header.h. when i try to add delegate for myviewcontroller it shows error like this."does not conform the protocol for WATokenViewDelegate".

am using this line instead of your code. I think this is the main problem.please see this

func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject)

{

}

-(void)tokenFieldView:(WATokenFieldView *)tokenFieldView didDeleteTokenWithId:(id)tokenId

{

}

On Tue, Feb 9, 2016 at 4:05 PM, Wendy notifications@github.com wrote:

Hi,

Have you set the delegate for the tokenFieldView ? _tokenFieldView.delegate = self;

Cheers

— Reply to this email directly or view it on GitHub https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181807500 .

wendyabrantes commented 8 years ago

Yes thats the issue in swift you need to conform to the protocol WATokenFieldViewDelegate

class YourClassname : UIViewController, WATokenFieldViewDelegate{

//in the class where you use the tokenView.delegate = self //you need to implement the method for the WATokenFieldViewDelegate }

please check the objective-c example, the method to implement are under

pragma mark TOKEN VIEW

https://github.com/wendyabrantes/WATokenFieldView/blob/master/WATokenFieldViewExample/ViewController.m

On 9 February 2016 at 12:14, Sasikumariosdeveloper <notifications@github.com

wrote:

Hai,

am using this library file into my swift project. so i could add header files i bridging header.h. when i try to add delegate for myviewcontroller it shows error like this."does not conform the protocol for WATokenViewDelegate".

am using this line instead of your code. I think this is the main problem.please see this

func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject)

{

}

-(void)tokenFieldView:(WATokenFieldView *)tokenFieldView didDeleteTokenWithId:(id)tokenId

{

}

On Tue, Feb 9, 2016 at 4:05 PM, Wendy notifications@github.com wrote:

Hi,

Have you set the delegate for the tokenFieldView ? _tokenFieldView.delegate = self;

Cheers

— Reply to this email directly or view it on GitHub < https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181807500

.

— Reply to this email directly or view it on GitHub https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181841677 .

Wendy Abrantes, London +44711678138

Sasikumariosdeveloper commented 8 years ago

Hai,

//Am using Like this,

class AddPeopleViewController: UIViewController,UITableViewDelegate, UITableViewDataSource,ABNewPersonViewControllerDelegate, WATokenFieldViewDelegate

{

}

//create object for WATokenFieldView,

var tokenFieldViewRef:WATokenFieldView = WATokenFieldView()

//set the delegate inside viewDidLoad,

tokenFieldViewRef.delegate = self

// Writting WATokenFieldViewDelegate methods outside the didReceiveMemoryWarning()

// MARK: - WATokenFieldViewDelegate

func tokenFieldView(tokenFieldView: WATokenFieldView, didChangeHeight

height: CGFloat) {

    if height != tokenFieldView.frame.size.height {

        tokenViewHeight = height

        UIView.animateWithDuration(0.3, animations: {() -> Void in

            self.doLayout()

        })

    }

}

 func tokenFieldView(tokenFieldView: WATokenFieldView,

didChangeSearchStatus searchIsActive: Bool, byClearingTextField: Bool) {

    if !searchIsActive {

        tableViewList.reloadData()

    }

}

func beginSearchWithName(paramName: String) {

// var predicate: NSPredicate = NSPredicate(format: "(first_name CONTAINS[cd] %@) || (last_name CONTAINS[cd] %@)", paramName, paramName)

// filteredFriendsData = allFriendsData.filteredArrayUsingPredicate(predicate)

// currentData = filteredFriendsData

    tableViewList.reloadData()

}

 func tokenFieldView(tokenFieldView: WATokenFieldView, didChangeText

text: String)

{

    self.beginSearchWithName(text)

}

func tokenFieldView(tokenFieldView: WATokenFieldView,

didDeleteTokenWithId tokenId: AnyObject)

{

    if tokenFieldViewRef == tokenFieldView

    {

        if tokenId.isKindOfClass(NSString.self)

        {

            let selectedRows = (tableViewList.indexPathsForSelectedRows)

            for indexPath: NSIndexPath in selectedRows!

            {

                if strContactNames == tokenId as! String

                {

                    tableViewList.deselectRowAtIndexPath(indexPath,

animated: false)

                }

            }

        }

    }

}

But when i Click the X button in keyboard, func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject) did not called. Please give a proper idea or correct me.

Thanks in Advance.

On Tue, Feb 9, 2016 at 5:57 PM, Wendy notifications@github.com wrote:

Yes thats the issue in swift you need to conform to the protocol WATokenFieldViewDelegate

class YourClassname : UIViewController, WATokenFieldViewDelegate{

//in the class where you use the tokenView.delegate = self //you need to implement the method for the WATokenFieldViewDelegate }

please check the objective-c example, the method to implement are under

pragma mark TOKEN VIEW

https://github.com/wendyabrantes/WATokenFieldView/blob/master/WATokenFieldViewExample/ViewController.m

On 9 February 2016 at 12:14, Sasikumariosdeveloper < notifications@github.com

wrote:

Hai,

am using this library file into my swift project. so i could add header files i bridging header.h. when i try to add delegate for myviewcontroller it shows error like this."does not conform the protocol for WATokenViewDelegate".

am using this line instead of your code. I think this is the main problem.please see this

func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject)

{

}

-(void)tokenFieldView:(WATokenFieldView *)tokenFieldView didDeleteTokenWithId:(id)tokenId

{

}

On Tue, Feb 9, 2016 at 4:05 PM, Wendy notifications@github.com wrote:

Hi,

Have you set the delegate for the tokenFieldView ? _tokenFieldView.delegate = self;

Cheers

— Reply to this email directly or view it on GitHub <

https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181807500

.

— Reply to this email directly or view it on GitHub < https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181841677

.

Wendy Abrantes, London +44711678138

— Reply to this email directly or view it on GitHub https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181844731 .

Sasikumariosdeveloper commented 8 years ago

Hai, Please give a reply mail. I am too struggling on this.Please help me.

On Wed, Feb 10, 2016 at 2:22 PM, Sasi kumar P sasikumar.p@nanonino.in wrote:

Hai,

//Am using Like this,

class AddPeopleViewController: UIViewController,UITableViewDelegate, UITableViewDataSource,ABNewPersonViewControllerDelegate, WATokenFieldViewDelegate

{

}

//create object for WATokenFieldView,

var tokenFieldViewRef:WATokenFieldView = WATokenFieldView()

//set the delegate inside viewDidLoad,

tokenFieldViewRef.delegate = self

// Writting WATokenFieldViewDelegate methods outside the didReceiveMemoryWarning()

// MARK: - WATokenFieldViewDelegate

func tokenFieldView(tokenFieldView: WATokenFieldView, didChangeHeight

height: CGFloat) {

    if height != tokenFieldView.frame.size.height {

        tokenViewHeight = height

        UIView.animateWithDuration(0.3, animations: {() -> Void in

            self.doLayout()

        })

    }

}

 func tokenFieldView(tokenFieldView: WATokenFieldView,

didChangeSearchStatus searchIsActive: Bool, byClearingTextField: Bool) {

    if !searchIsActive {

        tableViewList.reloadData()

    }

}

func beginSearchWithName(paramName: String) {

// var predicate: NSPredicate = NSPredicate(format: "(first_name CONTAINS[cd] %@) || (last_name CONTAINS[cd] %@)", paramName, paramName)

// filteredFriendsData = allFriendsData.filteredArrayUsingPredicate(predicate)

// currentData = filteredFriendsData

    tableViewList.reloadData()

}

 func tokenFieldView(tokenFieldView: WATokenFieldView, didChangeText

text: String)

{

    self.beginSearchWithName(text)

}

func tokenFieldView(tokenFieldView: WATokenFieldView,

didDeleteTokenWithId tokenId: AnyObject)

{

    if tokenFieldViewRef == tokenFieldView

    {

        if tokenId.isKindOfClass(NSString.self)

        {

            let selectedRows = (tableViewList.

indexPathsForSelectedRows)

            for indexPath: NSIndexPath in selectedRows!

            {

                if strContactNames == tokenId as! String

                {

                    tableViewList.deselectRowAtIndexPath(indexPath,

animated: false)

                }

            }

        }

    }

}

But when i Click the X button in keyboard, func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject) did not called. Please give a proper idea or correct me.

Thanks in Advance.

On Tue, Feb 9, 2016 at 5:57 PM, Wendy notifications@github.com wrote:

Yes thats the issue in swift you need to conform to the protocol WATokenFieldViewDelegate

class YourClassname : UIViewController, WATokenFieldViewDelegate{

//in the class where you use the tokenView.delegate = self //you need to implement the method for the WATokenFieldViewDelegate }

please check the objective-c example, the method to implement are under

pragma mark TOKEN VIEW

https://github.com/wendyabrantes/WATokenFieldView/blob/master/WATokenFieldViewExample/ViewController.m

On 9 February 2016 at 12:14, Sasikumariosdeveloper < notifications@github.com

wrote:

Hai,

am using this library file into my swift project. so i could add header files i bridging header.h. when i try to add delegate for myviewcontroller it shows error like this."does not conform the protocol for WATokenViewDelegate".

am using this line instead of your code. I think this is the main problem.please see this

func tokenFieldView(tokenFieldView: WATokenFieldView, didDeleteTokenWithId tokenId: AnyObject)

{

}

-(void)tokenFieldView:(WATokenFieldView *)tokenFieldView didDeleteTokenWithId:(id)tokenId

{

}

On Tue, Feb 9, 2016 at 4:05 PM, Wendy notifications@github.com wrote:

Hi,

Have you set the delegate for the tokenFieldView ? _tokenFieldView.delegate = self;

Cheers

— Reply to this email directly or view it on GitHub <

https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181807500

.

— Reply to this email directly or view it on GitHub < https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181841677

.

Wendy Abrantes, London +44711678138

— Reply to this email directly or view it on GitHub https://github.com/wendyabrantes/WATokenFieldView/issues/1#issuecomment-181844731 .

wendyabrantes commented 8 years ago

How do you add a token ? you should be using _tokenFieldView.addToken(<#T##title: String!##String!#>, tokenId: <#T##AnyObject!#>, animated: <#T##Bool#>) when you delete if the object tokenID is equal to the one you've added didDeleteTokenWithId will be call. Try to manually add a token in view did load _tokenFieldView.addToken("test", tokenId: "fakeTokenID", animated: false)