使用“故事板"将数据插入我的数据库表时出错,即“没有可见的界面......"? [英] Getting error while inserting data to my table in database using 'storyboard' i.e "no visible interface..."?

查看:29
本文介绍了使用“故事板"将数据插入我的数据库表时出错,即“没有可见的界面......"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 IOS 的新手,这是我对它的第一个 crud 操作,我将这个应用程序命名为 BIDDatabaseApp

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.

我收到错误 No visible @interface for BidProducts 声明了选择器 nameProddescProd,它们都是 处的属性>BidProducts ,以及 NSArrayaddObject

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

现在我正在做的是在 Sqlite 中创建一个数据库,并使用带有 3 个按钮的故事板来添加视图和删除.

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.

好的,这是我的文件层次结构BIDProducts.hNSObject 的子类

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在 BIDViewcontroller.h 文件中,我正在导入 sqlite3.h 它是 xcode 没有通过代码获取它我正在以静态方式编写它并且它没有给出任何错误并且它也没有与数据库建立连接.我仍然无法连接数据库.

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

推荐答案

设置属性的语法错误,应该是

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

 products.nameProd = self.txtNameFeild.text;

编译器翻译成等价物

[products setNameProd:self.txtNameFeild.text];

并且 arrayOFProducts 应该声明为 NSMutableArray如果您想向其中添加对象.

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

(请注意,您可以从源代码中删除 @synthesize 语句,当前的 Clang 编译器会自动合成属性.)

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

这篇关于使用“故事板"将数据插入我的数据库表时出错,即“没有可见的界面......"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆