1

If you take a look at the picture I provided, on the left hand side there is a table. This table loads SQLite data. The SQLite data has some data retrieved from a MYSQL database. The SQLite data is the following columns:

StoreID, StoreName, StoreAddr, StoreHost, StorePort, StoreUser, StorePass, StoreDB.

What's showing up in the table cell is clearly the StoreName and StoreAddr

On the right hand side of my picture, you can see some code that is implemented for the didSelectRowAtIndexPath method. The selection of a cell causes a segue to a view controller that calls MYSQL data specific to the SQLite credentials from the cell. For example, if I clicked Latin Bites Peruvian Cuisine, it should use the SQLite credentials to log into MYSQL and then parse the information back to the program.

My question is: How do I have the 'Latin Bites' cell grab SQLite info to be used as MYSQL credentials?

I can't target each individual cell's data. If there was just one entry in SQLite, then I would do a code similar to this:

    sqlite3_stmt *statement;

if (sqlite3_open([dbPathString UTF8String], &companyDB)==SQLITE_OK) {
    [arrayOfStore removeAllObjects];

    NSString *querySql = [NSString stringWithFormat:@"SELECT * FROM storelist"];
    const char* query_sql = [querySql UTF8String];

    if (sqlite3_prepare(companyDB, query_sql, -1, &statement, NULL)==SQLITE_OK) {
        while (sqlite3_step(statement)==SQLITE_ROW) {


            // Statement 1,2,3 etc. relates to the SQLite table in order.

            NSString *name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 1)];
            NSString *address = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 2)];
            NSString *host = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 3)];
            NSString *pass = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 6)];
            NSString *db = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statement, 7)];





            NSString *dateString = [NSDateFormatter localizedStringFromDate:[NSDate date]
                                                                  dateStyle:NSDateFormatterShortStyle
                                                                  timeStyle:NSDateFormatterFullStyle];



            NSString *salesStr = @"http://";
            salesStr = [salesStr stringByAppendingString:host];
            salesStr = [salesStr stringByAppendingString:@":8080/sales.php?password="];
            salesStr = [salesStr stringByAppendingString:pass];
            salesStr = [salesStr stringByAppendingString:@"&db="];
            salesStr = [salesStr stringByAppendingString:db];
            salesStr = [salesStr stringByAppendingString:@"&edate="];
            salesStr = [salesStr stringByAppendingString:dateString];
            salesStr = [salesStr stringByAppendingString:@"&sdate="];
            salesStr = [salesStr stringByAppendingString:dateString];



NSURL * url = [NSURL URLWithString:salesStr];
NSData * data = [NSData dataWithContentsOfURL:url];



json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];


NSLog(@"response type is %@",[json class]);

//Set up our cities array



storesArray = [[NSMutableArray alloc]init];

            for (int i = 0; i < json.count; i++)



            {


            NSString * netSales = [[json objectAtIndex:i] objectForKey:@"netSales"];
            NSString * voids = [[json objectAtIndex:i] objectForKey:@"voidSales"];
            NSString * discounts = [[json objectAtIndex:i] objectForKey:@"discountSales"];
            NSString * guestCount = [[json objectAtIndex:i] objectForKey:@"guestCount"];
            NSString * peopleServed = [[json objectAtIndex:i] objectForKey:@"servedCount"];
            NSString * employeesClock = [[json objectAtIndex:i] objectForKey:@"loggedIn"];




            Store * myStore = [[Store alloc]initWithNetSales: (NSString *) netSales andVoids: (NSString *) voids andDiscounts: (NSString *) discounts andGuestCount: (NSString *) guestCount andPeopleServed: (NSString *) peopleServed andEmployeesClock: (NSString *) employeesClock];




   [storesArray addObject:myStore];


But I need to have each individual cell pull it's SQLite data to be used as MYSQL credentials. Any suggestions?

my SQLite table and related cell selection information

francojay
  • 323
  • 1
  • 12

1 Answers1

2

Note. This answer is very old. These days almost everything involes a container view: https://stackoverflow.com/a/23403979/294884 Depending on the app, you will likely have to use containers everywhere.


Here are the critical steps for making a table with custom view cells. Custom cells are used in every table you will ever make (it's rather silly that they are presented as "optional").

enter image description here

enter image description here

The code below "FancyCell" is what's being pointed to in the second image.

Step one .. in you .h file for the custom cell, add an IBOutlet button.

@interface FancyCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UIButton *testeButtton;

In the .m file put a function "clickedOnTesteButton".

In storyboard click on the CELL, put a button IN that CELL (NOT in the table view).

Drag outlets from the button to the CELL which will now be called "FancyCell". So, drag to the MIDDLE LEFT RED ARROW - NOT the TOP left red arrow.

Don't forget, at "CRITICAL" in the first image above, type in the custom cell type.


Regarding your earlier question content: BTW these days, you can just write

json[i][@"netSales"]

So for your custom cell, something like...

@interface FancyCell : UITableViewCell

-(void)useThisInfo:(OneEntryTableRow *)oepr;

@property (nonatomic, strong) IBOutlet UITextViewTidy *mainPostText;
@property (nonatomic, strong) IBOutlet UILabel *greenTagText;
@property (nonatomic, strong) IBOutlet UILabel *authorFullname;
.. many of these...
@end
Community
  • 1
  • 1
Fattie
  • 30,632
  • 54
  • 336
  • 607
  • Do I have a custom cell: No, I don't I suppose... Am I using storyboard or pre-storyboard: I'm using both. Storyboard for all view controllers besides the 'DetailViewController.xib' – francojay May 22 '14 at 20:52
  • Thanks for the input, by the way. I've been programming for a little over a month so I appreciate any help. – francojay May 22 '14 at 20:53
  • Thank you Joe :) Will use all of this information to get what I need. – francojay May 22 '14 at 21:02
  • After hours of trial and error, I have hit a dead end... Perhaps I could ask of further assistance? – francojay May 23 '14 at 03:59
  • Great! I definitely understand custom cell classes now. So in my case, I want to have each cell fetch the host ip, database, and password (which is stored in a SQLite .db file.) So for example, the Latin bites cell in the table is simply fetching SQLite data. (The name and address from relative statements.) I need, when clicked, to also fetch the relative host ip, database, and password. After it fetches the info, then it segues to a new view controller and displays the jSON parsed info relative to it's credentials stored in SQLite. So then for the custom class cell I would input da frst code? – francojay May 23 '14 at 23:11
  • You'll almost certainly have somewhere just a simple static class, say, (or maybe a singleton) that literally does the database call. your SquirrelCell would just call that class. It would be poor engineering to literally put that code literally in the SquirrelCell code base. So be sure to do that! :) – Fattie May 24 '14 at 07:10