Giter Club home page Giter Club logo

titokenfield's Introduction

TITokenField

Kinda like an NSTokenField for iOS (see Messages / Mail apps).

Usage

See the "TokenFieldExample" app for details on usage. It's limited at the moment to one tokenising field and a content view below because it's pulled straight from one of my apps. Multiple field support requires tweaking.

ARC?

Yup

License

This control is dual licensed:
You can use it for free under the BSD licence below or, 
If you require non-attribution you can purchase the commercial licence available at http://www.cocoacontrols.com/authors/thermogl

Copyright (c) 2012 - 2013 Tom Irving. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY TOM IRVING "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOM IRVING OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

titokenfield's People

Contributors

arthurpalves avatar ata-n avatar dillan avatar evanwalsh avatar jkoehl avatar jmig avatar lordkev avatar manveer avatar nagrao avatar rex-remind101 avatar thermogl avatar yimingtang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

titokenfield's Issues

New tag version (for CocoaPods)

The current version of TITokenField on CocoaPods is from six months ago. Even if TITokenField isn't ready for a 1.0 release, it would be great to have some of the more recent changes available through CocoaPods. It seems like this would entail making a new tag as well as creating an updated spec here. That being said, simply making a new tag would be sufficient since that would enable someone else to update the spec.

Access to token objects

Similar to tokenTitles, but instead of an array of strings return the array of represented objects?

crash when shouldAdd=NO

Hi,
I think there is a bug in the TITokenField#addToken method when the delegate discards the adding of a token.

- (TIToken *)addTokenWithTitle:(NSString *)title {
    if (title.length){
        TIToken * token = [[TIToken alloc] initWithTitle:title representedObject:nil font:self.font];
        [self addToken:token];
        [token release];
        return token;
    }
    return nil;
}

If shouldAdd says NO, [self addToken:token] will not retain the token so we end up with a TiToken with 1 retain count and we release it. The it returns a released object which crashes.

This method should return an autoreleased object:

- (TIToken *)addTokenWithTitle:(NSString *)title {
    if (title.length){
        TIToken * token = [[TIToken alloc] initWithTitle:title representedObject:nil font:self.font];
        [self addToken:token];
        return [token autorelease];
    }
    return nil;
}

cheers ;)

Single line mode option

It would be nice if there were a single line mode option, where instead of creating more vertical space for the field as tokens are added it scrolled horizontally instead.

Cannot use enablesReturnKeyAutomatically

I wish to use enablesReturnKeyAutomatically with my TITokenField.

Of course I can set it to YES, but it winds up not doing anything. My guess? the kTextEmpty and/or kTextHidden are not visible to the eye, but they are there and thus the text of the field is non-zero. And so, the field never is truly empty and so the Return key never disables.

I'd like to be able to use enablesReturnKeyAutomatically, but due to the hidden non-empty text, can't. :-(

why does it always scroll to top?

in method tokenField:didAddToken: , i scroll it to point (0 , tokenField.frame.size.height - 42) , but when i input a new character , it will scroll to top . why? and how can i to block it ?

TokenFieldView not scroll properly

To reproduce. Enter email address until the token field goes behind the keyboard. Now if you try to scroll you will get trouble scrolling it. But if you scroll by holding a token then you can scroll. But it should behave like apple's default mail composer.

Tapping the Delete multiple times creates delete loop

Steps to Reproduce:

  1. Add 5-6 items.
  2. Delete any middle item using backspace. You can delete item of second / third position. Then observe cursor went automatically at last position.
  3. Now tap delete 2 times. Doing this delete loop will occur. And all delete will be vanished.

Reproducibility: 3 out 5 cases.

Am I missing something ? Please revert back as soon as possible so that i can fix the problem at my end.

Warning: Implicit conversion from enumeration type 'TITokenFieldControlEvents' to different enumeration type 'UIControlEvents' (aka 'enum UIControlEvents')

The following warning appears in Xcode 'Implicit conversion from enumeration type 'TITokenFieldControlEvents' to different enumeration type 'UIControlEvents' (aka 'enum UIControlEvents')' for lines 70, 71, 743, and 746.

E.g.
[_tokenField addTarget:self action:@selector(tokenFieldFrameWillChange:) forControlEvents:TITokenFieldControlEventFrameWillChange];
[_tokenField addTarget:self action:@selector(tokenFieldFrameDidChange:) forControlEvents:TITokenFieldControlEventFrameDidChange];

Typecasting 'TITokenFieldControlEventFrameWillChange' to UIControlEvents will fix this.

screen shot 2013-06-21 at 12 18 48 pm

Changing Alignment

Hello

is there a way to change the alignment of the tokens to be right-aligned instead of left

i am working on an arabic application where i need the tokens to be right aligned

is there a way to do that ??

Ability to use "represented object" instead of strings

I would like to be able to give the sourceArray an array of objects instead of strings. This would give me more flexibility to customize how it is displayed in the results, the string that is used by the search, and the string that is displayed in the token.

For example, if I type in "mi", I would like "Michael Enriquez (home) 123-123-1234" to show up in the results. Then when it is selected, I would want only "Michael Enriquez" to show up in the token. Also, I wouldn't want the "(home)" part to be matched as a result.

This would be similar to how the NSTokenField works for the Mac. See NSTokenFieldDelegate Protocol: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSTokenFieldDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSTokenFieldDelegate/tokenField:representedObjectForEditingString:

Is this something that can be easily supported?

Adding same email twice (or more) will show redundant tokens

For example add email: [email protected] then space and same email again.
When token field will loose focus you will see those 2 emails

I have fixed it with:

  • (void)addToken:(TIToken *)token {

    BOOL shouldAdd = YES;
    if ([delegate respondsToSelector:@selector(tokenField:willAddToken:)]){
    shouldAdd = [delegate tokenField:self willAddToken:token];
    }

    if (shouldAdd){

    [self becomeFirstResponder];
    
    [token addTarget:self action:@selector(tokenTouchDown:) forControlEvents:UIControlEventTouchDown];
    [token addTarget:self action:@selector(tokenTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    if ( ![self.subviews containsObject:token] )
        [self addSubview:token];
    
    if (![_tokens containsObject:token]) {
    
        [_tokens addObject:token];
    
        if ([delegate respondsToSelector:@selector(tokenField:didAddToken:)]){
            [delegate tokenField:self didAddToken:token];
        }
    
        [_placeHolderLabel setHidden:YES];
    }
    
    [self setResultsModeEnabled:NO];
    [self deselectSelectedToken];
    

    }
    }

and adding this to TIToken

  • (BOOL)isEqual:(id)object
    {
    if ( [object isKindOfClass:[self class]] == NO )
    return NO;

    TIToken* t = (TIToken*)object;
    return [t.title isEqualToString:self.title];
    }

Hide popoverController properly on iPad

Problem

In the example application, if I tap the first letter of a name (e.g. "a" for Albert Deltoro), the popoverController appears it works fine. But if I tap the first two letters of a name (e.g. "al" for Albert Deltoro), the popoverController disappears.

Cause

This is because setSearchResultsVisible: method is called in tableView:numberOfRowsInSection:, which is called several times by several calls from [resultsTable reloadData];. In the one letter case, it is called 3 times, and in the two letter case, it is called twice (which I couldn't figure out), and sometimes setSearchResultsVisible: hides popoverController because the resultsArray is empty.

Solution

Move the line [self setSearchResultsVisible:(resultsArray.count > 0)]; from tableView:numberOfRowsInSection: to the end of resultsForSubstring:substring: so that display/hide popoverController operation is only carried out once at the end of search.

Scrolling while To: field takes up the whole screen above keyboard

I've noticed that once someone creates enough tokens that they fill the available part of the screen (keyboard to top) there is no way to scroll the whole view so I can get out of the tokenField so that it resigns firstResponder status and goes back to original size again. If any piece of the view underneath is visible I can grab it and scroll, or just tap inside it so it becomes first responder, but that becomes impossible when the tokenField takes up all of the visible section of the screen

Simple enhancements - recipients label and popover position

I am trying to use your token field as a tags field rather than as a recipient field. For this reason it'd be useful to allow users to customise the ' x recipients' label that appears when the field is full.
Also, as I'd like the field can to appear in different places (rather than just the top of the screen) it would also be useful to customise the allowed positions of the UIPopoverArrow. Not sure if there is an easy fix for the tableview, as it gets slightly unworkable when the field is placed near the bottom of the screen (you get about 2 rows to deal with).

Results table has a crazy frame.

When the token field height is larger than the scroll view's height, the results table has a weird frame.

Probably just an issue with my height calculation code.

Will fix as soon as possible!

Bug using ContactPicker

Hey Tom,

thanks for this nice piece of code.
After playing around with it a bit I found an issue when using the ABPeoplePicker for the ButtonAction.

In your example project you just add a token manually when this button gets pressed. In reality when doing so the ABPeoplePicker is brought up and the tokenField resigns first responder.
Now when I add a token manually the tokenField will become responder after the token was added and this leads to the deletion of all previously added tokens. So before the new token is added the tokenField should rebuilt the saved tokens and then add the new token.

You can replicate this behavior by using this code in your example project:

- (void)showContactsPicker {

    // Show some kind of contacts picker in here.
    // For now, it's a good chance to show how to add tokens.
    [tokenFieldView.tokenField resignFirstResponder];
    [tokenFieldView.tokenField addToken:@"New Name"];

    // You can access token titles with 'tokenFieldView.tokenTitles'.
    // Eg, NSLog(@"%@", tokenFieldView.tokenTitles);
}

Thanks again

Tokens became selected in tableView when the cell is reloaded

I've a TITokenField in the contentView of a UITabelViewCell, when the table reload its data the tokens became selected.

Actually my code is something like this:

if (IHaveSomeValueFromTheTokensSaved) {

     add the tokens
     deselect the selected token
}

But I still have the tokens selected.
It's a bug, or I'm missing something?

ARC ? Anyone?

I have tried and failed miserably to convert this over to ARC. Do you know anyone who has converted it?
Thanx in Advance

Crashes when modalView is closed from delegate

#pragma mark View Handlers
- (void)layoutTokensAnimated:(BOOL)animated {
    CGFloat newHeight = [self layoutTokensInternal];
    if (self.bounds.size.height != newHeight){
        
        // Animating this seems to invoke the triple-tap-delete-key-loop-problem-thing™
        [UIView animateWithDuration:(animated ? 0.3 : 0) animations:^{
            [self setFrame:((CGRect){self.frame.origin, {self.bounds.size.width, newHeight}})];
            [self sendActionsForControlEvents:TITokenFieldControlEventFrameWillChange];
            
        } completion:^(BOOL complete){
            [self sendActionsForControlEvents:TITokenFieldControlEventFrameDidChange]; //Crashes on this line
        }];
    }
}

TITokenField scroll to the last token

If there are many tokens in the token filed, it can be scrolled. The token field will scroll to the last token position whenever one of the token is touched. How could i forbid this? As the touched token could be scrolled out of the view, it is not that user friendly.

Display issues when used within a UITabBarController

When displayed within a UITabBarController there is about 20 pixels that are blank below the UITableViewController used for the search results.

If you change the didFinishLaunchingWithOptions in the sample project to the code below you reproduce this.

I'm going to continue troubleshooting tonight/tomorrow and will submit a patch if I can find the issue. What I've found so far is the frame passed to initWithFrame is the same size regardless to the tabbar so inside the component there must be some calculation that is getting thrown off. The behavior is the same regardless of the hidesBottomBarWhenPushed BOOL.

Thanks for the awesome component!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    TokenFieldExampleViewController * viewController = [[TokenFieldExampleViewController alloc] init];
    UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [tabBarController addChildViewController:navigationController];
    [viewController release];

    [window setRootViewController:tabBarController];
//    [window setRootViewController:navigationController]
    [navigationController release];

    [window makeKeyAndVisible];

    return YES;
}

search results table view looks wrong on iOS 7

Hi folks,

Please find the issue in the below image (the screenshot is taken from your latest example app):
ios simulator screen shot sep 26 2013 11 07 28 am

I'm still trying to locate the wrong calculation but since you're more familiar with it i guess it will take less for you to fix it.

Thank you for your effort,

Ziv

TITokenField scroll to the last token

If there are many tokens in the token filed, it can be scrolled. The token field will scroll to the last token position whenever one of the token is touched. How could i forbid this? As the touched token could be scrolled out of the view, it is not that user friendly.

placeHolderLabel off by exactly 3 pixels

The place holder for the tokenfield view is off by three pixels as seen in the example project.

In line 808 of TITokenField.m replace this:

label = [[UILabel alloc] initWithFrame:CGRectMake(_tokenCaret.x, _tokenCaret.y + 2, self.rightView.bounds.size.width, self.rightView.bounds.size.height)];

with this:

label = [[UILabel alloc] initWithFrame:CGRectMake(_tokenCaret.x + 3, _tokenCaret.y + 2, self.rightView.bounds.size.width, self.rightView.bounds.size.height)];

screen shot 2013-06-22 at 11 28 37 am

This:
screen shot 2013-06-22 at 11 29 17 am

vs This:

screen shot 2013-06-22 at 11 28 56 am

Tapping the Delete key three times creates delete loop

After entering a bunch of tokens into the field, tapping the delete key (virtual keyboard) three times sends a delete loop to the field, deleting every token, until another key is tapped, overriding this delete loop.

Still looking into the cause - created an issue for historical reference :)

Thanks to Mr Artichaut for finding this problem.

tokenField:willAddToken: get called at strange moment

I'm trying to prevent user from adding duplicated token, and trying to limit maximum token counts.

So I try to do some checking like this:

- (BOOL)tokenField:(TITokenField *)tokenField willAddToken:(TIToken *)token {
  NSArray *titles = tokenField.tokenTitles;
  for (NSString *title in titles) {
    if ([title isEqualToString:token.title]) {
      // Prompt: duplicate!
      return NO;
    }
  }
  return (titles.count < kICDMaxNumberOfTags);
}

I'll prompt user that he is trying to add duplicated token.

But I found that this method gets called while tokenField begins editing and ends editing, which makes the prompt shows up if tokenField isn't empty.

I'm curious why addToken gets called when tokenField begins/ends editing.
Any idea?

addTokenWithTitle:respresentedObject:

Hi,
this is a small enhancement request. Add a helper method for adding tokens with objects. Currently, only the method which also specifies the Font is exposed but a caller might not want to specify the font all the time

#pragma mark Token Handling

- (TIToken *)addTokenWithTitle:(NSString *)title respresentedObject:(id)object {

    if (title.length){
        TIToken * token = [[TIToken alloc] initWithTitle:title representedObject:object font:self.font];
        [self addToken:token];
        //[token release];
        return [token autorelease];
    }

    return nil;
}

token view "bounces" when typing in autocomplete beyond the first line

To reproduce:

  • start app
  • type "a"
  • select the first entry
  • type "a" again
  • select the first entry (you're now in the second line)
  • start typing a name, e.g. "arlean"

Result: after every letter the top view that contains the tokens scrolls up or down - showing either 1 line or 2 lines on screen.

It's possible that the answer from here http://stackoverflow.com/questions/4585718 (with adding an extra UIScrollView) would help, but I didn't have enough time to implement this.

Support placeholders

It would be nice if TITokenField supported the inherited placeholder property.

Selection list not disappearing with pods installation

Not sure if this is a bug or an error on my part but with my pods installation, and a complete copy of your example app, the contact selection popover or table view doesn't disappear when a contact is selected.
The example app works perfectly, it's just the pod installation.

I can provide all my code, but it is just a copy and paste of your example code downloaded from this repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.