Как использовать поиск по индексу в tableView? - PullRequest
1 голос
/ 18 мая 2011

В моем табличном представлении имена и заголовки поступают с сервера через xml-разбор, как только будет показано ниже.

in figure1 name and title are comes from server through xml parsing

В этом списке табличных представлений я хочу использовать индексированный поиск, как показано на рисунке ниже. Как я могу это сделать?

image

Ответы [ 2 ]

0 голосов
/ 14 мая 2019

Шаг - 1: Создайте UItableView на вашей доске рассказов. - Источник данных, делегат

Шаг - 2: импорт - UITableViewDelegate, UITableViewDataSource

Шаг - 3: Методы реализации

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return self.arr.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! MyCell
    cell.selectionStyle = .none
    let dictData = self.arr[indexPath.row] as? NSMutableDictionary
    let image = dictData?.object(forKey: "image") as! String
    cell.lblSchoolName?.text = dictData?.object(forKey: "name") as? String
    cell.lblSchoolAddress?.text = dictData?.object(forKey: "address") as? String
    cell.img?.sd_setImage(with: URL(string: image), placeholderImage: UIImage(named: "splash screen-test-compress.jpg"), options: [.continueInBackground,.lowPriority], completed: {(image,error,cacheType,url) in

        if error == nil
        {
            cell.img?.image = image
        }
        else
        {
            cell.img?.image =  UIImage(named: "splash screen-test-compress.jpg")
        }
    })
    return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    let dictData = self.arrAll[indexPath.row] as! NSMutableDictionary
    let AllEvent_VC = self.storyboard?.instantiateViewController(withIdentifier: "AllEvent_VC") as! AllEvent_VC
    let strSlug = String(dictData.object(forKey: "slug") as! String)
    AllEvent_VC.strSlug = strSlug
    self.navigationController?.pushViewController(AllEvent_VC, animated: true)
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 100
}

// self.TableViewHeight.constant = CGFloat (self.arrAllSchoolByDistData.count * 100) //self.view.updateConstraintsIfNeeded()

0 голосов
/ 18 мая 2011

Вы можете иметь Массив словарей, где каждый раздел будет представлен объектом словаря.Ключом словаря будет заголовок раздела, а значением будет массив строк в разделе.

Вы можете использовать NSPredicate для поиска возвращенного массива с сервера и создания массива источника данных. Руководство по программированию NSPredicate

iphone & Objective C - Фильтрация массива с использованием NSPredicate

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...