I have an application in which I want to fetch content from a database using a particular ID column and later display all that content in textfields on a button press. The snippet below shows how I fetch the content in an array.
//this is a function which i am created which will be called in button click event
-(NSArray*)getStudents
{
NSMutableArray *studentArray=[[NSMutableArray alloc]init];
sqlite3_stmt *statement = nil;
NSString *query=@"select * from UserInformation where UserId=?";
const char *sql = [query cStringUsingEncoding:NSUTF8StringEncoding];
if (sqlite3_prepare_v2(dbConnection, sql, -1, &statement, NULL) == SQLITE_OK) {
while(sqlite3_step(statement) == SQLITE_ROW) {
Student *newStudent=[[Student alloc]init];
newStudent.age=sqlite3_column_int(statement, 0);
newStudent.name=[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
[studentArray addObject:newStudent];
}
}
return studentArray;
}
I have a problem adding this array to my textfields so that when I click on the button my textfields are loaded with the values from the database for a particular userid. I have written the above function in one of my controllers and my textfields are defined in another controller. How do I fill the above array in my textfields?
USe below as reference code ..