GithubHelp home page GithubHelp logo

janzhao / zjchoosenamebyabc Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 1.0 650 KB

类似通讯录的方式选择人名、地名、学校名等各种名称。(可以用作通讯录或者城市地名选择)

License: Apache License 2.0

Objective-C 82.64% C 17.36%

zjchoosenamebyabc's Introduction

ZJChooseNameByABC

类似通讯录的方式选择人名、地名、学校名等各种名称。(可以用作通讯录或者城市地名选择)

//选择学校例子 image

//搜索学校例子 image

详细用法见Demo:

//选择人名或者地名

  • (void)selectNameABC
    {

    //测试用数据 NSString *tmpStr = @"{"STATUS":"0","result":[{"schoolId":"123","schoolName":"清华大学"}, {"schoolId":"456","schoolName":"北京大学"}],"total":"1"}";

    NSDictionary *tmpDict = [NSJSONSerialization JSONObjectWithData:[tmpStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];

    NSMutableArray *sourceArr = [[NSMutableArray alloc]init]; sourceArr = tmpDict[@"result"];

    NSMutableArray *array = [[NSMutableArray alloc]init];

    for (int i = 0; i < [sourceArr count]; i++) { NSDictionary *dic = sourceArr[i];

      ChineseString *item  = [[ChineseString alloc] init];
      item.hanzi           = dic[@"schoolName"];
      item.pinyinAllLetter = dic[@"schoolName"];
      item.idStr           = dic[@"schoolId"];
      
      
      NSString *pinYinResult=[NSString string];
      
      for(int j=0;j<item.hanzi.length;j++)
      {
          NSString *singlePinyinLetter=[[NSString stringWithFormat:@"%c",pinyinFirstLetter([item.hanzi characterAtIndex:j])]uppercaseString];
          
          pinYinResult=[pinYinResult stringByAppendingString:singlePinyinLetter];
      }
      
      item.pinYin=pinYinResult;
      
      [array addObject:item];
    

    } NSArray *sectionIndexTitlesArr = [ChineseString IndexArray:array]; NSArray *sectionArr = [ChineseString LetterSortArray:array];

    ZJChooseNameByABCViewController *vc = [[ZJChooseNameByABCViewController alloc]init]; vc.nameArray = array; vc.sectionIndexTitlesArr = sectionIndexTitlesArr; vc.sectionArr = sectionArr;

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; nav.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:nav animated:YES completion:nil]; }

zjchoosenamebyabc's People

Contributors

janzhao avatar

Stargazers

iGhibli avatar duxinfeng avatar li avatar CodeX avatar  avatar  avatar LUDY2015 avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

badadu

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.