0

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

请对我温柔,我只是一个学习者,我很难调试这个在此处输入图像描述问题。

我收到错误 No visible @interface for BidProductsDeclarations the selectors nameProdand descProdwhich are the properties at BidProducts, and the same error on NSArraywithaddObject

现在我正在做的是我已经创建了一个数据库,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
4

1 回答 1

0

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

 products.nameProd = self.txtNameFeild.text;

编译器将其转换为等价物

[products setNameProd:self.txtNameFeild.text];

并且arrayOFProducts应该声明为NSMutableArray 好像要向其添加对象。

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

于 2013-09-12T17:34:53.967 回答