I'm relatively new to iOS programming, so please bear with me.
I'm creating an app that calls recipes from a table view, then listing the measurements and ingredients as labels in the detail view. I catalogued my recipes in Google Sheets, downloaded it as a .csv file and populated a table using SQLiteStudio. I then exported the database, and using FMDB, plopped it in my app. Everything works fine there and I'm able to retrieve various fields.
What I'm trying to do is list out the measurements and ingredients so that it displays with line breaks:
0.5 oz. 1.0 oz. 1 jigger
And not as: 0.5 oz., 1.0 oz., 1 jigger which is how I wrote it into the Google doc.
I've tried using \n in the SQLite viewer but it outputs it as a String rather than encoding it as a new line. However, when I view the accompanying .sql file, TextMate2 reads it as new lines. I'm not sure if I have to apply some code within my tableviewcontroller implementation file where I call the FMDB or elsewhere.
I have been looking for a solution for awhile now but no luck. Any help in steering me in the right direction would be greatly appreciated. Thanks!
CocktailListTableViewController.m
- (NSMutableArray *)recipeCocktails {
recipeCocktails = [[NSMutableArray alloc] init];
NSString *databasePath = [(AppDelegate *) [[UIApplication sharedApplication] delegate] databasePath];
FMDatabase *fmDB = [FMDatabase databaseWithPath:databasePath];
if(![fmDB open])
{
NSLog(@"Could not open DB, try again");
return nil;
}
FMResultSet *results = nil;
results = [fmDB executeQuery:@"SELECT * FROM recipesCocktails"];
NSLog(@"result %@ ",results);
if ([fmDB hadError]) {
NSLog(@"DB Error %d: %@", [fmDB lastErrorCode], [fmDB lastErrorMessage]);
}
while ([results next]) {
Cocktails *cocktails = [[Cocktails alloc] init];
cocktails.recipeName = [results stringForColumn:@"recipeName"];
cocktails.recipeMeasure = [results stringForColumn:@"recipeMeasure"];
cocktails.recipeIngred = [results stringForColumn:@"recipeIngred"];
cocktails.recipeGlass = [results stringForColumn:@"recipeGlass"];
cocktails.recipeShaker = [results stringForColumn:@"recipeShaker"];
cocktails.recipeDirections = [results stringForColumn:@"recipeDirections"];
[recipeCocktails addObject:cocktails];
}
[fmDB close];
return recipeCocktails;
CocktailsDetailTableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = cocktails.recipeName;
self.recipeIngred.text = cocktails.recipeIngred;
self.recipeMeasure.text = cocktails.recipeMeasure;
Aucun commentaire:
Enregistrer un commentaire