Getting error while inserting data to my table in database using 'storyboard' i.e “no visible interface…”?

有些话、适合烂在心里 提交于 2020-01-25 23:43:07

问题


I'm new to IOS and this is My first crud operation on it And I named this App As BIDDatabaseApp

Kindly be gentle with me i am just a learner i am getting difficulty to debug this

problem.

I'm getting the error No visible @interface for BidProducts declares the selector nameProd and descProd which both are the properties at BidProducts , and the same error on NSArray with addObject

Now what i am doing is that i have make a database in Sqlite and use the storyboard with 3buttons for add view and delete.

OK, and this is my file hierarchy BIDProducts.h Sub-Class of 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 here in BIDViewcontroller.h file i am importing the sqlite3.h it is xcode is not getting it by code i am writing it in a static way and it is not giving any error and it is not making a connection with the db also. I am still not able to connect with database.

#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

回答1:


Your syntax to set a property is wrong, it should be

 products.nameProd = self.txtNameFeild.text;

which the compiler translates to the equivalent

[products setNameProd:self.txtNameFeild.text];

And arrayOFProducts should be declared as NSMutableArray if you want to add objects to it.

(Note that you can remove the @synthesize statements from your source code, the current Clang compiler synthesizes properties automatically.)



来源:https://stackoverflow.com/questions/18770693/getting-error-while-inserting-data-to-my-table-in-database-using-storyboard-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!