데이터베이스를 호출하는 클래스를 만들기 위해 Database.h와 Database.m을 모두 만드는 하위 클래스 NSObject "Database"를 만들었습니다.
나는 이와 같은 코드를 만들었습니다.
#import "Database.h"
@implementation Database
NSString* docsDir;
NSArray* dirPaths;
NSString* dbsePath;
NSString *getDB()
{
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
dbsePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"DBUntilAgo.sqlite"]];
NSLog(@"1!%@",dbsePath);
return dbsePath;
}
@end
맞습니까? 다른 뷰로 전화를 걸려면 어떻게해야합니까? pls 도움. Im Xcode를 처음 사용합니다.
이것은 Database.h 파일이어야합니다.
@interface Database: NSObject
{
}
-(NSString *)getDB;
@end
이것은 Database.m 파일이어야합니다.
#import "Database.h"
@implementation Database
-(NSString *)getDB {
NSString* docsDir;
NSArray* dirPaths;
NSString* dbsePath;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
dbsePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"DBUntilAgo.sqlite"]];
NSLog(@"1!%@",dbsePath);
return dbsePath; }
@end
그런 다음 AppDelegate.m에서 다음과 같이 만들 수 있습니다.
#import "AppDelegate.h"
#import "Database.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
Database *db=[[Database alloc] init];
NSLog(@"%@",[db getDB]);
// RootNavigationController *root=[[RootNavigationController alloc] initWithRootViewController:[RootNavigationController RootViewControllerCandidate]];
// [root setNavigationBarHidden:YES];
// [self.window setRootViewController:root];
[self.window makeKeyAndVisible];
return YES;
}
@end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다