Iphone 用于从sqlite DB获取数据的NSObject类通过NSmutuable to UItableview类返回null
我想从UIViewcontroller类中的数据库访问DBhelper类中获取的数据,我已经导入了类,创建了对象,方法和所有变量都可以在UIViewcontroller类中访问。当通过uiviewcontroller类调用方法时,它们显示的是数据库结果或分配给它们的任何方法,但当通过对象在uiviewcontroller中使用这些变量/数组时,它们返回null。即使我也实现了属性并综合了它们。。这是我的密码Iphone 用于从sqlite DB获取数据的NSObject类通过NSmutuable to UItableview类返回null,iphone,objective-c,xcode,sqlite,Iphone,Objective C,Xcode,Sqlite,我想从UIViewcontroller类中的数据库访问DBhelper类中获取的数据,我已经导入了类,创建了对象,方法和所有变量都可以在UIViewcontroller类中访问。当通过uiviewcontroller类调用方法时,它们显示的是数据库结果或分配给它们的任何方法,但当通过对象在uiviewcontroller中使用这些变量/数组时,它们返回null。即使我也实现了属性并综合了它们。。这是我的密码 -(NSMutableArray *) SaveDBInArray { [se
-(NSMutableArray *) SaveDBInArray {
[self createEditableCopyOfDatabaseIfNeeded];
[self initializeDatabase];
const char *sql = "SELECT * FROM table11";
if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) {
//NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); }
while (sqlite3_step(init_statement) == SQLITE_ROW) {
colum1= [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,0)];
colum2= [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,1)];
allEnteries=[[NSMutableArray alloc]init];
[allEnteries addObject:colum1];
[allEnteries addObject:colum2];
}
NSLog(@"array with values %@",allEnteries );
//HERE WHENEVER METHOD IS BEING CALLED IT IS DISPLAYING ONLY TOP ONE VALUE FROM EACH COLUM BUT I WANT ALL OF THEM
sqlite3_reset(init_statement);
[self closeDatabase];
return allEnteries;
}
您的DBhelper类代码 你们一次又一次地初始化数组,你们应该使用下面的代码
\\Initialize array here
yourtableviewclass*yourclass= [yourtableviewclassalloc]init];
dbH.allEnteries=[[NSMutableArray alloc]init];
\\\\\\\ you must create property of allEnteries array in yourtableviewclassclass and
synhtesize it. and then try to access that array with following 2 line code in ur tableview class
yourtableviewclass *obj = [yourtableviewclass alloc]init ];
nslog("%@"obj.yourtableviewclass );
while (sqlite3_step(init_statement) == SQLITE_ROW) {
colum1= [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,0)];
colum2= [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement,1)];
[yourclass.allEnteries addObject:colum1];
[yourclass.allEnteries addObject:colum2];
}
Yourtableviewclas.h代码
@界面Yourtableviewclas:uiviewcontroller{
NSMUTABLEARRY*allentries;
}
@属性(非计时)nsmutablearray Allentries
@结束
Yourtableviewclas.m代码
synthesize allEnteries ;
-(void)viewdidload{
yourtableviewclass *obj = [yourtableviewclass alloc]init ];
nslog("%@"obj.allEnteries );
}
我可以知道你编辑了《兄弟》的哪一部分吗?顺便说一句,感谢改进:)[Thank alloc]initWitLove]xD..它在数组中显示了数据库表的所有值,但另一个问题是,当我在uitable视图类中调用此数组时,它返回null,即使我已经实现了nsmutuable数组的属性,您能帮我一下吗?objDBhelper=[[DBhelper alloc]init];NSLog(@“这是表类%@”,objDBhelper.allentries);[超级视图下载];在viewcontroller中,我调用了viewdidload函数如果我没有错,我认为DBhelper是另一个类,您编写的有问题的代码在不同的类中。因此,如果正确,请使用更新的应答并在DBhelper类中不初始化AllEntries数组没有旧的很好,有问题的代码在DBhelper类中,我想将存储在dbhelper类中声明的数组中的数据提取到表类。。。看,3个类,A,B,C A=viewcontroller B=Dbhelper,在数据库中获取更新插入数据并将其存储在数组allEntries C=uitableview类中,我必须使用该数组在表视图中显示它。问题是,当我在C(表)类中调用它时,数组显示null