我是 IOS 新手,这是我对它的第一次 crud 操作,我将此应用程序命名为BIDDatabaseApp
请对我温柔,我只是一个学习者,我很难调试这个问题。
我收到错误 No visible @interface for BidProducts
Declarations the selectors nameProd
and descProd
which are the properties at BidProducts
, and the same error on NSArray
withaddObject
现在我正在做的是我已经创建了一个数据库,Sqlite
并使用带有 3 个按钮的情节提要来添加视图和删除。
好的,这是我的文件层次结构 BIDProducts.h NSObject 的子类
#import <Foundation/Foundation.h>
@interface BIDProducts : NSObject
@property (nonatomic, strong)NSString *nameProd;
@property (nonatomic, strong)NSString *descProd;
@end
BIDProducts.h
#import "BIDProducts.h"
@implementation BIDProducts
@synthesize nameProd,descProd;
@end
BIDViewController.h 在 BIDViewcontroller.h 文件中我正在导入 sqlite3.h 它是 xcode 没有通过代码获取它我正在以静态方式编写它并且它没有给出任何错误并且它没有与数据库建立连接还。我仍然无法连接数据库。
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "BIDProducts.h"
@interface BIDViewController : UIViewController<UITableViewDataSource , UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtNameFeild;
@property (weak, nonatomic) IBOutlet UITextField *txtDescFeild;
@property (weak, nonatomic) IBOutlet UITableView *txtAreaViewList;
- (IBAction)btnAddProduct:(id)sender;
- (IBAction)btnDeleteProduct:(id)sender;
- (IBAction)btnViewProduct:(id)sender;
@end
BIDViewController.M
#import "BIDViewController.h"
#import "BIDProducts.h"
@interface BIDViewController ()
{
NSArray *arrayOFProducts;
sqlite3 *productsDB;
NSString *dbPathString;
}
@end
@implementation BIDViewController
- (void)viewDidLoad
{
[super viewDidLoad];
arrayOFProducts = [[NSMutableArray alloc]init];
[[self txtAreaViewList]setDelegate:self];
[[self txtAreaViewList]setDataSource:self];
[self createOrOpenDb];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)createOrOpenDb
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *docPath = [path objectAtIndex:0];
dbPathString = [docPath stringByAppendingPathComponent:@"productsDB.sqlite"];
char *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dbPathString]) {
const char *dbPath = [dbPathString UTF8String];
if (sqlite3_open(dbPath, &productsDB) == SQLITE_OK) {
const char *sqlStmt = "CREATE TABLE IF NOT EXISTS TBLLISTPRODUCT (ID INTEGER PRIMERYKEY AUTOINCREMENT, PRODNAME VARCHAR, PRODDESC VARCHAR ) ";
sqlite3_exec(productsDB, sqlStmt, NULL, NULL, &error);
sqlite3_close(productsDB);
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrayOFProducts count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
BIDProducts *aProduct = [arrayOFProducts objectAtIndex:indexPath.row];
cell.textLabel.text = aProduct.nameProd;
cell.textLabel.text = aProduct.descProd;
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnAddProduct:(id)sender {
char *error;
if (sqlite3_open([dbPathString UTF8String], &productsDB) == SQLITE_OK) {
NSString *insertStmt = [NSString stringWithFormat:@"INSERT INTO TBLLISTPRODUCT(PRODNAME,PRODDESC) values ('%s', '%s') ", [self.txtNameFeild.text UTF8String] , [self.txtDescFeild.text UTF8String]];
const char *insert_stmt = [insertStmt UTF8String];
if (sqlite3_exec(productsDB, insert_stmt, NULL, NULL, &error) == SQLITE_OK) {
NSLog(@"person added");
BIDProducts *products = [[BIDProducts alloc]init];
[products nameProd:self.txtNameFeild.text];
[products descProd:self.txtDescFeild.text];
[arrayOFProducts addObject:products];
}
sqlite3_close(productsDB);
}
}
- (IBAction)btnDeleteProduct:(id)sender {
}
- (IBAction)btnViewProduct:(id)sender {
}
@end