I am brand new with SQLite. I have a UITableview in which there are different days. (Monday to Sunday). When I click, for example, on Monday, another view node also contains a UITableview inside it. In the same viewcontroller, I have a UIButton, when I click on it, I can add data to the SQLite [ A ] database, I insert the name and day of the week (Day of the week in this example is βMondayβ, because I clicked on the view controller on Monday).
When I insert a name , it appears in my table view. But when I return to my first view manager with days, and I, for example, click, for example, on Wednesday, the added data also appears there.
So my question is; How can I show the name that I inserted on Monday, only on Monday, and not on other days (tables)
Additional Information:
Therefore, when the user adds the name on Monday, I send the dayoftheweek with the added name to the SQLite database, when the user adds the name on Wednesday, I send the dayoftheweek on Wednesday, etc.
Coffee database looks like
CoffeeName | dayoftheweek ------------------------- Hello world | Monday Hello Planet | Wednesday Hello Animal | Monday Hello STOVW | Friday
[A] const char *sql = "insert into Coffee(CoffeeName, dayoftheweek) Values(?, ?)";
I need to check if the day (for example) is Monday same as dayoftheweek (Monday), and then display all items containing "dayoftheweek monday"
My sqlite looks like this:
+ (void) getInitialDataToDisplay:(NSString *)dbPath { if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { const char *sql = "select coffeeID, coffeeName from coffee"; sqlite3_stmt *selectstmt; if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) { while(sqlite3_step(selectstmt) == SQLITE_ROW) { NSInteger primaryKey = sqlite3_column_int(selectstmt, 0); Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey]; coffeeObj.LessonName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; coffeeObj.dayoftheweek = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; coffeeObj.isDirty = NO; [appDelegate.coffeeArray addObject:coffeeObj]; } } } else sqlite3_close(database);
Insert:
coffeeObj.dayoftheweek = [NSString stringWithFormat:@"%@", dayoftheweek];
this insert: monday tuesday wednesday thursday friday saturday or sunday
But how can I display the data that is inserted on Monday in the form of a table on Monday and the data that is inserted on Tuesday in the time controller, etc.
I tried;
if([coffeeObj.dayoftheweek isEqualToString:@"Monday"]) { cell.day.text = coffeeObj.LessonName; } else { }
Display:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CustomCellIdentifier = @"DaycusViewController"; DaycusViewController *cell = (DaycusViewController *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DaycusViewController" owner:self options:nil]; for (id oneObject in nib) if ([oneObject isKindOfClass:[DaycusViewController class]]) cell = (DaycusViewController *)oneObject; }
/ * begin * / if ([CoffeeObj.dayoftheweek isEqualToString: @ "Monday"]) {
// cell.Name.text = CoffeeObj.CoffeeID; //cell.Day.text = CoffeeObj.dayoftheweek; } else { } /* end */ //it need to display in this example only things where dayoftheweek is monday but. return cell; }
call to getInitialDataToDisplay function