searching Problem
i am fetching data from database ,and i am showing result on labels ,data is coming from one table, i want to search a specific word from the present table view ,,, i want if the desired world is exist in the present table view then its clr should be change,
开发者_开发百科any one can help me :)(I am devlping app in Iphone)
Regards Haseeb
All you need to do is that once you get the desired data from database (Which I guess can be an array) call this method [tableViewPtr reloadData]
and in the TableView Delegate Method. cellForRowAtIndexPath:
Here tableViewPtr is your outlet for tableview .Inside the delegate method search for the text string and If found you can either set a background image else update the cell accordingly
As you have mentioned that you are taking the input for search text using a Textfield in an alert view you can grab the input string from the alert View using somthing like this
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
searchString = myTextField.text;
if(searchString)
{
[myTable reloadData];
}
[myTextField resignFirstResponder];
}
}
Here myTextField is the textField that was added to the alertView
And In the cellForRowAtIndexPath: method you can compare this string with the content of the cell
if (searchString != nil)
{
if([searchString caseInsensitiveCompare:currentCellText] == 0)
{
change the desired property for cell
}
}
here myTextField is a TextField and searchString is an NSString declared in .h file
精彩评论