1

こんにちは友達私のアクティビティの 1 つで、カスタム テキスト フィールドを作成しました。50 個のレコードを持つ配列があり、配列レコードをロードするためのカスタム テーブルを作成します。テキスト フィールドに入力すると、配列レコードがフィルターされ、テーブルビューで欲求レコードを取得...

UITextField *patientname=[[UITextField alloc]initWithFrame:CGRectMake(130,10,170,30)];
patientname.font = [UIFont boldSystemFontOfSize:15.0];
patientname.tag=1;
//the horizontal alignment of the text
patientname.textAlignment = NSTextAlignmentLeft;
patientname.borderStyle = UITextBorderStyleBezel;
patientname.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
patientname.clearButtonMode = UITextFieldViewModeWhileEditing; 
patientname.delegate =self;
[Self.view addSubview:patientname];

これは私の配列です...

Array Name (
"Mr. Ram  Singh",
"Mr.   ",
"Master DSHKJLKD  null mfkmlkdfsg",
"Mr. Rajat  Jain",
"Mrs. Sonali K Singh",
"Mr. Amit  Singh",
"Mr. Paan  Singh",
"Mr. Ajit  Singh",
"Dr. Rohan  Sharma",
"Mr. Arpita  Tripathi",
"Mr. Jacky  Chain",
"Ms. Malini  Ramani",
"Mr. Ankit  Chavan",
"Mr. Ankit  Gupta",
"Ms. Ragini  Khanna",
"Mr. Raj  Kumar",
"Mr. Manish  gupta",
"Mr. Anshul  Aggarwal",
"Ms. Priya  Ranjith",
"Mr. Sdf Sdf Sdf",
"Mr. Sanyam  Jain",
"Mr. Rakesh  Gupta",
"Mr. Vishnu  Gupta",
"Mr. Shabbir K Malik",
"Mr. mohan  gupta",
"Mr. Sajat  Jain",
"Mr.   ",
"Mr. ravi  kapoor",
"Miss Mona  Hdjdbshs",
"Mr. test new  demo",
"Mr. Devdas  Gupta",
"Mr. Tarun  Malik",
"Mr. Mayank  Sharma",
"Miss Rachits  Guptas",
"Mr. Test T Patient",
"Mr. Manish  Kumar",
"Mr. Asd Asd Asd",
"Mr. NARENDRA  Garg",
"Mr. ritik  gupta",
"Mr. Mohd  Salim",
"Mr. Anshul  Garg",
"Ms. tanvi  anand",
"Mr. ashish  singh",
"Mr. Navdeep  Bora",
"Mr. Rajat  Kumar",
"Mr. shardul  negi",
"Mr. Shrey  Bhalla",
"Mr.   ",
"Mr. Dushyant  Sharma",
"Mr. Ritesh  Kapoor",
"Mr. Jamna  Das",
"Mr. hello  patient",
"Mr. Ashish  Vashisht",
"Ms. Prachi  Pant",
"Mr.   ",
"Mr. Sunil Kumar Singh",
"Mr. Mohd  Ali",
"Mr. Jay  Singh",
"Mr. Pantient  Patient",
"Mr. paitent  demo",
"Mr. adi  df",
"Mr. Anamika  Gupta",
"Mr. Subh  Karmakar",
"Mrs. Kirshna  Kumar",
"Mr. Jay  Kishan",
"Mr. Ram  Singh",
"Mr. Jagjeet  Singh",
"Mr. Badal  Yadav",
"Mr. Isha  Bhalla",
"Mr. Saadhna  Gupta",
"Mr. Tar  Un",
"Mr. SR  Khan",
"Mr. amar  nath",
"Mr. ankur  kaul",
"Mr. Qwe Qwe Qwe",
"Ms. Fgh Fgh Fgh",
"Mr. Kishan  Lal",
"Mrs. Kkkk Kkk Kkk",
"Mr. radha  gupta",
"Mrs. Meena  Sharma",
"Mr. Charu  Jain",
"Mr. dsf  df",
"Mr. Testdemo  Demotest",
"Mr.   ",
"Mr.   ",
"Mr. Yogendra  Singh",
"Mr.   ",
"Mr. rachit  Gupta",
"Mr. Raman  Malhotra",
"Mr. American  Jain",
"Mr. aakash  gandhi",
"Mr. Mohd  Ali",
"Mr.   ",
"Mr. Arpit  Gupta",
"Mr. nitish  Kumar",
"Mr. Drupad  Jain",
"Mr. Ashish  Moza",
"Mr. Rajat  Jain",
"Mr. Shan  Kumar",
"Mrs. Mahinder  Kapoor",
"Mr.   ",
"Ms. megha  priya",
"Ms. lata  gupta",
"Mr. Test  Patientb",
"Dr. Himanshu Kumar Parashar",
"Mr. Gfh  Gfh",
"Mr.   ",
"Mr. ZX  Zxc",
"Ms. manvi  mehra",
"Mr. ramesh  Babu",
"Mr. Dushyant Kumar Sharma",
"Mr. Asd Asd Asd",
"Mr. Rachit  Gupta",
"Mr. Sachin  Kumar",
"Mr. Rakesh  Sharma",
"Mr.   ",
"Mr. Amit  Kumar",
"Mr. Ram Kumar Naresh",
"Mr.   ",
"Mr. John Kumar Cena",
"Mr. sahd  df",
"Mr. Asdfasd Asf Qweqwe",
"Mr. Sanjeev  Kumar",
"Mr. Geeta  Sharma",
"Mr. Ram  Kumar",
"Mr. Sunil  Rai",
"Mr. atul  gupta",
"Mr.   ",
"Mr. martin  luther",
"Mr. Asd Qwe Qwe",
"Mr. Test  Kumar",
"Mr. Shrey  Bhalla",
"Miss Neha  Jain",
"Ms. Anushka  Sharma",
"Miss Jaysheer  Jain",
"Mr. Fhdf Bgjgh ",
"Mr. Deepak  Gupta",
"Mr. Test  Patienta",
"Mr. Subh  Karmakar",
"Mr. Mohan  Kumar",
"Mr. apoorv  sharma",
"Mr. ankit  rathor",
"Mr. tarun  gupta",
"Mr. Mohd  Rizwan",
"Mr. hello  sd",
"Mr. Amit  Gupta",
"Mr. Dushyant 2nd  Sharma",
"Mr. anshul  aggarwal",
"Mr. Asd Asd Asd",
"Mr. Jitesh  Kumar",
"Mr. Hodor Hodor Hodor",
"Mr. Abhinav  Goel",
"Mr. Testz Z Patietn",
"Mr. Mohit  Dani",
"Mr.   ",
"Mr. Jinender  Jain",
"Mr. aditya  rai",
"Mr. Ankit Kjhk Loonia",
"Master Himanshu  Kumar",
"Mr. mohan  bhargav",
"Mr. Mohan  Kumar",
"Mr. Satypal  Kapoor",
"Mr. Mohit  Raina",
"Mr. Asd Qwe Qwe",
"Mr. test  test",
"Mr. Garima  Gupta",
"Mr. Mayank  Jain",
"Mr. Test  C"

) このデータは、... のようなカスタム テーブルにロードされます。

 table_SearchPatient=[[UITableView alloc]initWithFrame:CGRectMake(130,40,170,250)style:UITableViewStylePlain];
table_SearchPatient.delegate=self;
table_SearchPatient.dataSource=self;
table_SearchPatient.layer.borderWidth = 2.0;
table_SearchPatient.layer.borderColor = [UIColor grayColor].CGColor;
[self.view addSubview:table_SearchPatient];

このテーブルはすべてのデータを正常にロードし、必要な名前を検索するにはカスタムテキストフィールドを使用します....問題を解決してください..

4

4 に答える 4

2

UITextFieldDelegate とメソッドを実装する

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

このメソッドでは、テキスト フィールドに書き込むときに、配列内のテキストを検索し、フィルター処理された配列を埋めることができます。次に、reloadData を使用してテーブルをリロードします。

于 2013-09-05T07:15:09.130 に答える
0

検索バーを使用している場合は、テーブル配列から一時配列を作成します。そして、次の方法を使用します

-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)text
{
    if(text.length == 0)
    {
        isFiltered = FALSE;
        tableDataArray  = tempArray;
    }
    else
    {
        isFiltered = TRUE;
        NSMutableArray *searchArray = [NSMutableArray arrayWithArray:friendsArray];
        NSPredicate *predicate  = [NSPredicate predicateWithFormat:@"name contains[c] %@",text];
        tableDataArray  =[NSMutableArray arrayWithArray:[searchArray filteredArrayUsingPredicate:predicate]];

    }

    [self.tableView reloadData];
    [searchBar becomeFirstResponder];

}
于 2013-09-05T08:15:13.670 に答える