Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > iOS - ดึงข้อมูลมาจาก SQLite ให้โชว์ใน tableview ทำยังไงดีคับ output ข้างล่างก็โชว์นะคับ แต่พอ Simulator แล้วมันไม่โชว์อะคับ



 

iOS - ดึงข้อมูลมาจาก SQLite ให้โชว์ใน tableview ทำยังไงดีคับ output ข้างล่างก็โชว์นะคับ แต่พอ Simulator แล้วมันไม่โชว์อะคับ

 



Topic : 098671



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์




Code (Objective-C)
//
//  AppDelegate.h
//  ProjectTest
//
//  Created by Adullyarich on 8/4/56 BE.
//  Copyright (c) 2556 Adullyarich. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>{
    UIWindow *window;
    
}
@property (strong, nonatomic) UIWindow *window;


@end


Code (Objective-C)
//
//  AppDelegate.m
//  ProjectTest
//
//  Created by Adullyarich on 8/4/56 BE.
//  Copyright (c) 2556 Adullyarich. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate


@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}
							
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end



Code (Objective-C)
//
//  OrderViewController.h
//  ProjectTest
//
//  Created by Adullyarich on 8/4/56 BE.
//  Copyright (c) 2556 Adullyarich. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <sqlite3.h>
@interface OrderViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
    sqlite3 *database;
}

-(void)initDatabase;
-(void)getStudent;
@end


Code (Objective-C)
//
//  OrderViewController.m
//  ProjectTest
//
//  Created by Adullyarich on 8/4/56 BE.
//  Copyright (c) 2556 Adullyarich. All rights reserved.
//

#import "OrderViewController.h"



@implementation OrderViewController{
    NSMutableArray *listOfCid;
    NSMutableArray *listOfCname;
    NSMutableArray *listOfCadd;
}


- (void) initDatabase
{
	BOOL success;
	NSFileManager *fileManager = [NSFileManager defaultManager];
	NSError *error;
	NSArray *paths = NSSearchPathForDirectoriesInDomains
    (NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *writableDBPath = [documentsDirectory
                                stringByAppendingPathComponent:@"Project.sqlite"];
	success = [fileManager fileExistsAtPath:writableDBPath];
	if (success)
	{
		return;
	}
	NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Project.sqlite"];
	success = [fileManager copyItemAtPath:defaultDBPath
                                   toPath:writableDBPath error:&error];
	if (!success)
	{
        NSAssert1(0, @"Failed to create writable database file with message'%@'.", [error localizedDescription]);
                  }
                  }

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initDatabase];
    [self getStudent];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


- (void) getStudent
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains
    (NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *path = [documentsDirectory
                      stringByAppendingPathComponent:@"Project.sqlite"];
	if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
	{
		const char *sql = "SELECT * FROM Customer";
		sqlite3_stmt *searchStatement;
		if (sqlite3_prepare_v2(database, sql, -1,
                               &searchStatement, NULL) == SQLITE_OK){
            listOfCid = [[NSMutableArray alloc] init];
            listOfCname = [[NSMutableArray alloc] init];
            listOfCadd = [[NSMutableArray alloc] init];

		{
            while (sqlite3_step(searchStatement) == SQLITE_ROW) {
                NSString *cid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 1)];
                NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 2)];
                NSString *cadd = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 3)];
                
                NSLog(@"Cid: %@ ,Cname: %@,Cadd: %@",cid, name,cadd);
                [listOfCid addObject:cid];
                [listOfCname addObject:name];
                [listOfCadd addObject:cadd];
            
            }
        }
		}
		sqlite3_finalize(searchStatement);
	}
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return [listOfCid count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *simpleTableIdentifier =@"Cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if(cell == nil){
        //cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
    }
    cell.textLabel.text = [listOfCid objectAtIndex:indexPath.row];
    cell.detailTextLabel.text =[listOfCname objectAtIndex:indexPath.row];
    //cell.imageView.image =[UIImage imageNamed:@"thumbnail.png"];
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

@end


IOS
IOS1



Tag : Mobile, iOS, Objective-C







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-04 19:01:27 By : vasinchon View : 1157 Reply : 3
 

 

No. 1



โพสกระทู้ ( 114 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบช้าไปหรือเปล่า สงสัยได้คำตอบไปแล้ว

Code (Objective-C)
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-09 11:16:11 By : LindyFralin
 


 

No. 2

Guest


อย่างที่คุณ LindyFralin ตอบครับ

numberOfSectionsInTableView ให้ return ค่าด้วย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-09 16:53:57 By : ปลา
 

 

No. 3



โพสกระทู้ ( 17 )
บทความ ( 0 )



สถานะออฟไลน์


ไม่ช้าไปหรอกคับ เผื่อมีคน เจอปัญหาเดียวกัน ขอบคุณมากครับผม
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-10 10:30:36 By : vasinchon
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS - ดึงข้อมูลมาจาก SQLite ให้โชว์ใน tableview ทำยังไงดีคับ output ข้างล่างก็โชว์นะคับ แต่พอ Simulator แล้วมันไม่โชว์อะคับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่