ios - Line breaks using FMDB and Obj-C -


i'm relatively new ios programming, please bear me.

i'm creating app calls recipes table view, listing measurements , ingredients labels in detail view. catalogued recipes in google sheets, downloaded .csv file , populated table using sqlitestudio. exported database, , using fmdb, plopped in app. works fine there , i'm able retrieve various fields.

what i'm trying list out measurements , ingredients displays line breaks:

0.5 oz. 1.0 oz. 1 jigger

and not as: 0.5 oz., 1.0 oz., 1 jigger how wrote google doc.

i've tried using \n in sqlite viewer outputs string rather encoding new line. however, when view accompanying .sql file, textmate2 reads new lines. i'm not sure if have apply code within tableviewcontroller implementation file call fmdb or elsewhere.

i have been looking solution awhile no luck. in steering me in right direction 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 * 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]; // additional setup after loading view. self.title = cocktails.recipename; self.recipeingred.text = cocktails.recipeingred; self.recipemeasure.text = cocktails.recipemeasure; 

i can see you're trying store ingredients 1 long, pre-built string, , think approach not best.

it's gonna work, it's not future-friendly or simply... usual.

i suggest having new table knows possible ingredients, id's , other informations of (color, average weight, picture* , whatnot)

( please note it's not advised store images in sql database , you'd rather store references saved them files or url's)*

once have table, you're golden. reference array of ingredients in recipe table. example [1,27,133], , can want. have array of ingredient objects, can treat how see fit.

i would, example, loop on , create labels under each other , you'd have lines. use nsmutablestring , fill ingredients.name (again, using examples) fill uitextview newlines between each ingredient (by using nsmutablestring , adding newlines between each object name).

and more importantly, can modify without having re-work layouts or labels or re-write whole database because have static newlines ingredients each recipe.

that important point wanted make. approach can remove ingredient recipe without having think far or risk forgetting something. permanently destroy ingredient every recipe removing ingredient table. same adding new ones. or saying want change name of ingredient x, dont' have in every recipe, , on.

edit: answering question in comment

to load recipes in tableview , ingredients on detail page, can :

  • you load recipes in array , display (i think you're successful on part). note recipes have property called "ingredients" array of ingredient keys/ids/something

  • on cell tap, want load ingredients know id of, them array of id's stored in recipe, , select them db.

globally, have no idea ingredients until user taps : if don't need display them in table view, don't need laod them yet. know id (otherwise wouldn't able find them!).


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -