I would like to set UIPicker selected row by title, I'm using the code below, but it's not working, what I'm missing?
// data from sqlite db
test2 =[[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(statement, 1)];
NSLog(#"%#", test2); // 400 (the value)
[self.myPickerView selectRow:[[[NSUserDefaults
standardUserDefaults]objectForKey:test2]intValue] inComponent:0 animated:YES];
Related
I am inserting HTML content (which has special characters like bullets, etc) into the SQLite database.
When I try to get the content on a view, it does not show the special characters correctly. It shows me junk text.
How can I ensure that whatever text I insert in database, it is displayed correctly on the view.
Thanks!
My Insertion code:
// This query method implementation is in different file
- (NSArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args {
sqlite3_stmt *sqlStmt;
if (![self prepareSql:sql inStatament:(&sqlStmt)])
return nil;
int i = 0;
int queryParamCount = sqlite3_bind_parameter_count(sqlStmt);
while (i++ < queryParamCount)
[self bindObject:[args objectAtIndex:(i - 1)] toColumn:i inStatament:sqlStmt];
NSMutableArray *arrayList = [[NSMutableArray alloc] init]; // By Devang
int columnCount = sqlite3_column_count(sqlStmt);
while ([self hasData:sqlStmt]) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for (i = 0; i < columnCount; ++i) {
id columnName = [self columnName:sqlStmt columnIndex:i];
id columnData = [self columnData:sqlStmt columnIndex:i];
[dictionary setObject:columnData forKey:columnName];
}
[arrayList addObject:dictionary];
//[arrayList addObject:[dictionary autorelease]];
}
sqlite3_finalize(sqlStmt);
return arrayList;
}
// now call this method by make object for this file
NSString *inserQuery =[NSString stringWithFormat:#"insert into feedtest (title,summary,image,id) values ('%#','%#','%#',%d)",cell.textLabel.text,source,returnURL,indexPath.row];
NSLog(#"query - %#",inserQuery);
[database executeQuery:inserQuery];
// Retrive the data
NSString *sd=[NSString stringWithFormat:#"Select title,summary from feedtest"];
NSMutableArray *p=[[NSMutableArray alloc]init];
p=[[database executeQuery:sd ] mutableCopy];
[database close];
NSString *titleHTML = [[p objectAtIndex:i]valueForKey:#"title"];
NSString *postHTML =[[p objectAtIndex:i]valueForKey:#"summary"];
NSLog(#"%#",titleHTML);
NSLog(#"%#",postHTML);
You can check your local database using FireFox plugin SQLite. But, sometimes on retrieving we faced strange problem like what is present in the storage not coming properly and sometime, there is crash. So my suggestion is what you should check encoding scheme(normally, it's not matter more) and while getting data use this:
[NSString stringWithFormat:#"%s",(const char*)sqlite3_column_text(statement, 4)] ;
instead of:
[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 4)];
Hope, this is what you're looking for. Any concern get back to me. :)
I have a form contains text fields,a textView and 2 switches.Now I am using sqlite database for saving data in to database.Every thing is fine with text fields,text view saving,retrieving and even displaying the saved.As we know we don't have any feature called check box,we need to make use of switch which behaves/acts as that of check box functionality.Now while saving the switch state in to the database.I am saving it as a string/text format only,i.e. check the state of switch,assign value as '1' for ON and '0' for OFF to an integer.Now you might get a bit confused how can I save the integer to string format,yes you are right!I am converting the int value in to number and finally number to string.Then I have formed the query and have inserted the values in to sqlite database table.
Here is the code snippet of it for clear understanding:
int smsValue = 0;
if ([smsSwitch isOn])
{
smsValue = 1;
}
else
{
smsValue = 0;
}
NSNumber *smsNum = [NSNumber numberWithInt:smsValue];
NSString *selectedVal = [smsNum stringValue];
The selectedVal is what we are going to pass as string while forming the query,I also have found out that the state is getting saved properly,i.e. the value is correct.
Now I have a requirement,in my form I have switch for sms,Initially the state of that switch is Off,during off state,the last 2 fields i.e. textField and textView are hidden.If the user selects it (i.e. state is ON),then both the fields are said to be open to enter the values.
Totally I have saved 3 reminders,out of which I have saved 2 with out sms and 1 with sms and both the fields(last) filled.Now to pass the data,or to keep track of record saved after filling the form I have used a model class,please see the following snippet for clear understanding...how I have passed values for other fields(textFields):
-(void)viewDidLoad
{
textField.text = reminderInstance.Name;
textField1.text = reminderInstance.Event;
textField2.text = reminderInstance.Date;
textField3.text = reminderInstance.numDays;
textField4.text = reminderInstance.remGroup;
[super viewDidLoad];
}
Here the reminderInstance is object of the model class holding values like name,event,date etc...Now last 2 fields i.e. textField5 and textView are tied or linked to state of sms switch.If it is selected we need to consider both the fields values and pass them for user to edit/make changes.If not we need not bother about the last 2 fields.
Here is the action for the switch:
-(IBAction)toggleEnabledForswitch:(id)sender
{
if(smsSwitch.on)
{
textField5.hidden = NO;
textView.hidden = NO;
}
else
{
textField5.hidden = YES;
textView.hidden = YES;
}
}
Now in save action,I am checking the state of the switch and saving the values accordingly,the following code snippet will show a clear picture:
-(IBAction)save:(id)sender
{
int smsValue = 0;
if ([smsSwitch isOn])
{
smsValue = 1;
}
else
{
smsValue = 0;
}
NSNumber *smsNum = [NSNumber numberWithInt:smsValue];
NSString *selectedVal = [smsNum stringValue];
reminderInstance.smsString = selectedVal;
sqlite3_stmt *statement = nil;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK && textField.text != nil)
{
if (self.navigationItem.rightBarButtonItem.title == #"Save" && [textField.text length] !=0 && [textField1.text length] !=0 && [textField2.text length] !=0 && [textField3.text length] !=0 && [textField4.text length] !=0)
{
NSLog(#"am in the save loop");
if (smsValue == 0)
{
NSString *insertSQL = [NSString stringWithFormat:#"INSERT INTO reminders(name,event,date,bfr,grp,val,sms) VALUES (\"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\")", textField.text, textField1.text,textField2.text,textField3.text,textField4.text,isSelected,selectedVal];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(remindersDB, insert_stmt, -1, &statement, NULL);
}
else if (smsValue == 1)
{
NSString *insertSQL = [NSString stringWithFormat:#"INSERT INTO reminders(name,event,date,bfr,grp,val,sms,num,bod) VALUES (\"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\", \"%#\")", textField.text, textField1.text,textField2.text,textField3.text,textField4.text,isSelected,selectedVal,textField5.text,textView.text];
textField5.text = reminderInstance.number;
textView.text = reminderInstance.msgBody;
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(remindersDB, insert_stmt, -1, &statement, NULL);
}
if (sqlite3_step(statement) == SQLITE_DONE)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"\nReminder Saved" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil,nil];
[alert show];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Reminder not saved" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
}
}
I took another view controller with table view where I have populated a table view to view all the records that are being saved and upon selection we take him/her to the controller page that contains form i.e. populated with all the values.So far I have been successful in passing all the values using:
1.The following code in form controller page:
-(id) initWithReminder:(ReminderClass *)aReminder
{
if ( (self=[super init]) )
{
self.reminderInstance = aReminder;
}
return self;
}
2.The following parts of code in display controller:
-(void)loadReminders
{
// setup the reminders array
self.array = [[NSMutableArray alloc] init];
//Retrieve the values of database
const char *dbpath = [self.databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &remindersDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:#"SELECT * FROM reminders"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
ReminderClass *loadedReminder = [[ReminderClass alloc] init];
loadedReminder.reminderID = sqlite3_column_int(statement, 0);
loadedReminder.Name = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];
loadedReminder.Event = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
loadedReminder.Date = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
loadedReminder.numDays = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)]autorelease];
loadedReminder.remGroup = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 5)]autorelease];
loadedReminder.selString = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 6)]autorelease];
loadedReminder.smsString = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 7)]autorelease];
NSLog(#"selected value = %#",loadedReminder.smsString);
loadedReminder.number = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 8)]autorelease];
loadedReminder.msgBody = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 9)]autorelease];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
[dateFormat setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *theDate = [dateFormat dateFromString:loadedReminder.Date];
NSString *stringDate = [dateFormat stringFromDate:theDate];
loadedReminder.Date = stringDate;
NSLog(#"Date = %#",loadedReminder.Date);
[self.array addObject:loadedReminder];
[loadedReminder release];
}
sqlite3_finalize(statement);
}
sqlite3_close(self.remindersDB);
}
}
Now what is happening is since I have the table view in display controller with 2 containing fields except that are linked to sms state and one with all the fields filled.When I select the view controller it is crashing at line "loadedReminder.number":
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSPlaceholderString initWithUTF8String:]: NULL cString'
when I remove loadedReminder.number and loadedReminder.msgBody,we can view the table(controller page) no crash problem what so ever...Upon selection of table view cell I am doing the following:
-(void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ReminderClass *rem = [self.array objectAtIndex:indexPath.section];
// Instantiate your detail/editor view controller,
// and pass in the ReminderClass object to be edited.
ERAddReminderViewController *rdvc = [[[ERAddReminderViewController alloc]initWithReminder:rem]autorelease];
[self.navigationController pushViewController:rdvc animated:YES];
rdvc.navigationItem.rightBarButtonItem.title = #"Edit";
}
Now I can see all the values properly populated in fields,except the problem with switch.Because it is saving properly,but the switch is always in off state,the state set to default as I have already said during filling the form and saving it (if user selects it and fills the last 2 fields also) to save it(record).
Sorry for this huge description,just wanted to make it detailed,so that any one can understand what my issue is,I have made several searches.But unable to achieve the task.
Can any one please suggest me a way of how to save the switch state in database and then populate the same when loading records from database sqlite.
Thanks every one in advance :)
I found out the solution for it,i.e. use an NSString and assign string value i.e. the retrieved state values that were added to the array.Let me explain this in detail:
In Add Reminder page,take an NSString let's say currentState,now come back to where the saved reminders are viewed,take an array named "stateValues" and add the state values to that array i.e.:
loadedReminder.smsState = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 7)]autorelease];
[stateValues addObject:loadedReminder.smsState];
Now in did select row at index path,where we are navigating to add reminder page for editing or modifying the existing values of reminder,do this:
-(void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ReminderClass *rem = [self.array objectAtIndex:indexPath.section];
NSLog(#" switch state in did : %#",[stateValues objectAtIndex:indexPath.section]);
ERAddReminderViewController *rdvc = [[[ERAddReminderViewController alloc]initWithReminder:rem]autorelease];
rdvc.currentState = [stateValues objectAtIndex:indexPath.section];
}
We have successfully set the values to current state,now get back to add reminder page to set the state of switch,i.e. in viewDidLoad method do the following:
-(void)viewDidLoad
{
if ([currentState isEqualToString:#"0"])
{
[smsSwitch setOn:NO animated:NO];
}
else if([currentState isEqualToString:#"1"])
{
[smsSwitch setOn:YES animated:YES];
}
}
That's it,we have now set the state of switch properly by proper access of values that were saved for all consecutive reminders.
Hope it helps.Thank you!
I am trying to fetch and display contents from table.Currently i am running a query and store those id, and category name using NSMutableDictionary which works fine.
But I face one issue when i store the contents into NSMutableDictionary the order gets changed.When searching for this issue , it seems that this is the default behavior of the NSMutableDictionary.
I am not sure and how to use and what use to store the key pair value.
Please advice me that how can i overcome this problem
Thanks for stopping by...
//====================================================================
- ( NSMutableDictionary * ) getDataToDisplayTierOne:(NSString*)dbPath{
//====================================================================
NSMutableDictionary *aTierOneTemplateData = [[NSMutableDictionary alloc]init];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
const char *sql_query_stmt = "select * from main_categories";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql_query_stmt, -1, &selectstmt, NULL) == SQLITE_OK)
{
while(sqlite3_step(selectstmt) == SQLITE_ROW)
{
NSString *aValue = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(selectstmt, 1)];
NSString *aId = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(selectstmt, 0)];
[aTierOneTemplateData setObject:aId forKey:aValue];
[aValue release];
[aId release];
}
}
sqlite3_finalize(selectstmt);
}
sqlite3_close(database);
return aTierOneTemplateData;
}
Note : - I understand the limitations on using the nsmutabledictionery
so i expecting your advice to that how can i overcome / fetch id,
value in other way.please suggest
Updated
For example
Apple 1
Orange 2
Papaya 3
Actually i want that list to display it on my uitableview
Apple
Orange
Papaya
When tapping on each cell , i want to have its id value
for instance , i tap on Orange , now i want to have that id value as 2
Can you please tell me how to iterate over array of dictionery
Use NSMutableArray instead of NSMutableDictionary.
Change the declaration
NSMutableDictionary *aTierOneTemplateData = [[NSMutableDictionary alloc]init];
to
NSMutableArray *aTierOneTemplateList = [[NSMutableArray alloc]init];
And add the abjects to the array,
[aTierOneTemplateList addObject:aId];
And return the NSMutableArray,
return aTierOneTemplateList;
Edit:
If you modify the while loop as follows, you will get array of NSDictionarys with the same order.
NSString *aValue = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(selectstmt, 1)];
NSString *aId = [[NSString alloc] initWithUTF8String:
(const char *) sqlite3_column_text(selectstmt, 0)];
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:aValue,#"value",aId,#"key", nil];
[aTierOneTemplateList addObject:dict];
[dict release];
[aValue release];
[aId release];
Edit2:
Consider now in your tableviewcontroller, you have array of NSDictionarys (say aTierOneTemplateList).
In cellForRowAtIndexPath method,
NSDictionary *dict = [aTierOneTemplateList objectAtIndex:indexPath.row];
NSString *key = [dict objectForKey:#"key"];
NSString *value = [dict objectForKey:#"value"];
Similarly in didSelectRowAtIndexPath method.
Neither NSDictionary nor NSSet are ordered collections. If you want ordering, use NSArray. If you want to impose ordering, add objects to unordered collections that have their own index attribute.
Hi everyone and I wish a very happy new year!
I have 2 view controllers,One where the user fills all the fields in the table view and clicks save,the data gets inserted in to table of sqlite database,I have already succeded inserting,updating,retrieving data from sqlite database table.
The other view controller where the user can view the saved data(My case:reminder).I have displayed the data saved successfully,i.e. when I save a reminder a cell gets added in view reminder page and the reminder saved in the instance gets displayed,similarly for each and every saved reminder and so on...
The user would well be interested and in need for editing the content he/she saves.So I have placed a edit button and I have implemented the orientation and deletion of the cell,but how can I edit the cell,i.e. how can I make the cell navigate to the add reminder page where the data is saved for that instance(reminder) on user selection of cell(in my case:sections with single row).
I can make the user navigate to the add reminder page,but how can I access the values corresponding to that reminder contained in table view sections.
For the user to make changes to the reminder,say phone number,date,message body etc... or what ever it is.
I made several attempts,searched various links googling but couldn't find a suitable and effective solution.
Here is how I retrieved reminders based on user saves in add reminder page :
-(void)loadgReminders
{
self.frndsArray = nil;
self.frndsArray = [[NSMutableArray alloc]init];
//Retrieve the group of reminder
const char *thePath = [self.databasePath UTF8String];
sqlite3_stmt *statment;
if (sqlite3_open(thePath, &remindersDB) == SQLITE_OK)
{
NSString *getQuery = [NSString stringWithFormat:#"SELECT * FROM reminders WHERE Grp = 'Family'"];
const char *sqlite_stmt = [getQuery UTF8String];
if (sqlite3_prepare_v2(self.remindersDB, sqlite_stmt, -1, &statment, NULL) == SQLITE_OK)
{
while (sqlite3_step(statment) == SQLITE_ROW)
{
ReminderClass *remind = [[ReminderClass alloc]init];
remind.Name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 1)];
remind.Event = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 2)];
remind.Date = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 3)];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
[dateFormat setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:remind.Date];
[dateFormat setDateFormat:#"MMMM dd"];
NSString *dateVal = [dateFormat stringFromDate:date];
remind.Date = dateVal;
[self.frndsArray addObject:remind];
[remind release];
}
sqlite3_finalize(statment);
}
sqlite3_close(remindersDB);
}
}
Please help me out with valuable suggestions
Thanks all in advance :)
In your tableview delegate method:
cellForRowAtIndexPath:
you access a member of your frndsArray.
Similarly, when the user selects a row,
didSelectRowAtIndexPath:
is called on your delegate.
Just access the same member of the frndsArray (usually by indexPath.row), and pass this object to your detail/editing viewController, either in it's init method or by setting an iVar.
If you want to implement the SAVE operation in your detail view controller, you'll also need to pass the primary key to the detail VC, so it can do the sql update based on that key.
EDIT:
pseudo code:
-(void) tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ReminderClass *rem = (ReminderClass *)[self.frndsArray objectAtIndex:indexPath.row];
// Instantiate your detail/editor view controller,
// and pass in the ReminderClass object to be edited.
ReminderDetailViewController *rdvc = [[ReminderDetailViewController alloc] initWithReminder: rem];
[self.navigationController pushNavigationController:rdvc animated:YES];
[rdvc release];
}
EDIT 2: more psuedo code (you'll need to do the #import and #synthesize and dealloc also)
In ReminderDetailViewController.h add this:
#property(nonatomic, retain) ReminderClass *myLocalReminderInstance;
In ReminderDetailViewController.m, add this initializer method:
-(id) initWithReminder:(ReminderClass *)aReminder {
if ( (self=[super init]) ) {
self.myLocalReminderInstance = aReminder;
}
return self;
}
My iPhone application has a UITable View implemented with search functionality in it. The values in the table are grouped into sections from A-Z. Whenever a user tap on particular cell in the table it loads a detail view controller which gives all the values of that particular user. Now my problem is whenever I search some contact and tap on a particular user to check his detail view it always returns a contact starting with letter A. So, my doubt is how to implement this search functionality. Is there a way to get the name of the contact I tapped..Please check this screenshot.. For example if I search some contact starting with letter 'B' and tap on that contact it loads the detail view of a contact starting with letter 'A'. I get all the values from the database. Can you please help me out...
This is the code:
The code I wrote here is in a method:
I am getting all the contacts from database and assigning to an array contacts. Then I am grouping all the contacts according to the alphabets and grouping everything into a dictionary with keys as A-Z and values as name of contacts starting with these letters. Now when I search for a particular contact his name may start with either A ,B or Z..so in the search bar when I search for a particular contact for example a contact starting with letter Z, in this case it gives the details of a person with A. I want this to change so that whenever I tap on a particular contact it should load its details. I am unable to figure out how to do it..
contacts = [[db getContacts:#"Contacts"] componentsSeparatedByString:#","];
[db cleanup];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
NSString *charString;
for (int i=65; i<91; i++) {
charString = [NSString stringWithFormat:#"%c",(char *)i];
[tempArray addObject:charString];
}
[charString release];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
for (int i=0; i<[tempArray count]; i++) {
NSMutableArray *contactsByIndex = [[[NSMutableArray alloc] init]autorelease];
NSString *tempChar = [tempArray objectAtIndex:i];
for (int j=0; j<[contacts count]-1; j++)
{
NSString *test = [contacts objectAtIndex:j];
NSString *tempString = [test substringToIndex:1];
if ([tempString isEqualToString:tempChar]) {
[contactsByIndex addObject:[contacts objectAtIndex:j]];
}
}
[dict setObject:contactsByIndex forKey:[tempArray objectAtIndex:i]];
}
self.contactNames = dict;
NSArray *array = [[contactNames allKeys] sortedArrayUsingSelector:#selector(caseInsensitiveCompare:)];
self.contactKeys = array;
[dict release];
[tempArray release];
//---display the searchbar---
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeYes;
listOfContacts = [[NSMutableArray alloc] init];
for (NSString *key in array)
{
NSArray *contactsArray = [contactNames objectForKey:key];
for (NSString *name in contactsArray) {
[listOfContacts addObject:name];
}
}
- (void) searchContactsTableView {
//---clears the search result---
[searchResult removeAllObjects];
for (NSString *str in listOfContacts) {
NSRange titleResultsRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[searchResult addObject:str];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
NSString *selectedRow=nil;
if (isSearchOn) {
selectedRow=[searchResult objectAtIndex:indexPath.row];
}
DetailViewController *detailViewController;
int section_index=[indexPath indexAtPosition:[indexPath length]-2];
int sugarid_Index = [indexPath indexAtPosition: [indexPath length]-1];
NSString* sectionName=[contactKeys objectAtIndex:section_index];
NSLog(#"%#",sectionName);
//This is a method which gets the details of a particular contact based on the section and the row selected..Contacts is the table name
NSString *getContact=[db getId:#"Contacts" bySection:sectionName andIndex:sugarid_Index];
id=[db getContact:#"Contacts" id:getContact];
// Pass the selected object to the new view controller.
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
detailViewController.eachContact=contactForSugarId;
[self.navigationController pushViewController:detailViewController animated:YES];
}
When I search for a contact it should search for the name in database and should return its details. Is there a way to do it..please let me know or is there a way to get the name of the cell i.e. the contact name so that I can use that in one of my database methods to retrieve the details of the contact I selected.
Off hand it sounds like you're looking in the wrong array of contacts after the search. You need to have two arrays. One with all the contacts, and one with the filtered contacts. When you search, put all the results in order in the filtered list, and pull the details from that one.
Does this make sense?
If not, try posting a bit of code, and explaining your structure.