2016-04-23 6 views
1

私はSwiftの新人です。アルファベット順に配列をソートし、IOSの連絡先リストに表示されているものと同様のインデックス付きリストやサイドアルファベットを実装する方法が不思議ですスウィフトでこれはUIPickerViewでこれと同様に行うことが可能ですか?index for UIPickerView like UITableView?swiftを使ったUIPickerViewのインデックス付きリスト/サイドアルファベット

これは可能ですか?

のXcodeにHERESに私の現在のコード:

import UIKit 

class ViewController: UIViewController, UIPickerViewDataSource,UIPickerViewDelegate { 

@IBOutlet weak var friendSearch: UISearchBar! 
@IBOutlet weak var friendPicker: UIPickerView! 



let friendNames = ["Lisa Young","Mary Jenkins","Sarah Miller","Tina Clark","Melissa Jackson","Christine Edwards","Jane Taylor","Carol Stewart","Anne Brown","Sandra Simmons","Nicole Sanchez","Wanda Baker","Janice Wood","Gloria Wilson","Catherine Perry","Julie Thomas","Laura Watson","Alice Torres","Diane Diaz","Katherine Reed","Mildred Morgan","Carolyn Cooper","Beverly Johnson","Dorothy Smith","Nancy Anderson","Karen Peterson","Sara Turner","Rachel Barnes","Pamela Wright","Susan Brooks","Kathleen Lopez","Patricia Hall","Kathryn Foster","Janet Morris","Denise King","Lillian Bryant","Amy Robinson","Anna Allen","Stephanie Mitchell","Barbara Walker","Jessica Cox","Annie Richardson","Margaret Collins","Joan Russell","Louise Rogers","Jacqueline Long","Donna Murphy","Frances Sanders","Kelly Gonzales","Sharon Bennett","Linda Washington","Ashley Roberts","Teresa Hughes","Christina Nelson","Marie Thompson","Brenda Alexander","Doris Williams","Michelle Harris","Martha Parker","Norma Gonzalez","Emily Flores","Angela Garcia","Julia Martin","Betty Campbell","Cynthia Martinez","Elizabeth Davis","Diana Moore","Rose Griffin","Kathy Butler","Theresa Adams","Joyce Gray","Maria White","Jennifer Perez","Debra Hill","Andrea Lewis","Marilyn Cook","Virginia Price","Lois Carter","Deborah Powell","Shirley Scott","Kimberly Ramirez","Rebecca Bell","Irene Green","Evelyn Howard","Paula Kelly","Ruby Bailey","Jean Hernandez","Amanda Phillips","Lori James","Phyllis Lee","Ruth Jones","Judy Ward","Heather Evans","Helen Ross","Bonnie Rodriguez","Tammy Henderson","Cheryl Rivera","Ann Patterson","Judith Coleman"] 

var sortedFriends = [] 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    friendPicker.dataSource = self 
    friendPicker.delegate = self 

    if (friendSearch.text != nil) { 

    } 

    sortedFriends = friendNames.sort { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending } 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 
    return 1 
} 
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return sortedFriends.count 
} 

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
    return (sortedFriends[row] as! String) 
} 

}

答えて

0

IはUICollectionViewを使用し、フローレイアウトをカスタマイズし、それはUIPickerViewに似ているので、その後側にアルファベット・リストを追加。

関連する問題