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,038

HOME > Mobile > Mobile Forum > iOS รบกวนดูโค้ดให้หน่อยคะ เกี่ยวกับการรับค่าจากฐานข้อมูล


[Mobile] iOS รบกวนดูโค้ดให้หน่อยคะ เกี่ยวกับการรับค่าจากฐานข้อมูล

 
Topic : 111504



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



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



Code (Objective-C)
001.- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
002.{
003.    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
004.    if (self) {
005.        // Custom initialization
006.    }
007.    return self;
008.}
009. 
010. 
011.-(void)GetTableDataFromWeb{
012.    NSString *dict = [NSString stringWithFormat:@"{\"act\":\"placelist\",\"cid\":\"%d\",\"search\":\"%@\"}",infoRow+1,infoSearch];
013.    NSLog(dict);
014.    infoSearch = [NSString stringWithFormat:@""];
015.    MyAppCore *core = [[MyAppCore alloc] init];
016.    [core SendData2Server:dict rsObject:self];
017.     
018.}
019.-(void)GetDataFromServer:(id)rs
020.{
021.    NSLog(@"DATA MA LAEW mmmmmm : %@",rs);
022.    NSObject *obj_result = [rs objectForKey:@"res"];
023.    NSInteger iRes =[[NSString stringWithFormat:@"%@",obj_result] intValue];
024.    if(iRes>0){
025.        NSObject *obj_c = [rs objectForKey:@"count"];
026.        NSInteger iCount =[[NSString stringWithFormat:@"%@",obj_c] intValue];
027.        NSMutableArray *tempArray = [[NSMutableArray alloc] init];
028.        NSString *strData[10];
029.        for(int i=0;i<iCount;i++){
030.            NSObject *obj_id = [rs objectForKey:[NSString stringWithFormat:@"id%d",i]];
031.            NSInteger iID =[[NSString stringWithFormat:@"%@",obj_id] intValue];
032.            idArray[i] = iID;
033.             
034.            NSObject *obj_data = [rs objectForKey:[NSString stringWithFormat:@"data%d",i]];
035.            strData[i] =[NSString stringWithFormat:@"%@",obj_data];
036.             
037.            //NSLog([NSString stringWithFormat:@"i:%d id:%d data:%@",i,iID,strData]);
038.             
039.            //GDNTileObject *temp_tile = [[GDNTileObject alloc] init];
040.            //[tempArray addObject:strData];
041.        }
042.        [tempArray addObject:@"AAA"];
043.        //int count = sizeof(names)/sizeof(names[0]);
044.        NSArray *names_array = [NSArray arrayWithObjects:strData count:iCount];
045.        NSArray *infoArray = [NSArray arrayWithObjects:@"ร้านA",@"ร้านB",nil];
046.        tableInfo = names_array;
047.        [sendDataTable reloadData];
048.    }else{
049.        NSLog(@"NOT OK LA NA");
050.    }
051.}
052. 
053. 
054. 
055. 
056. 
057.- (void)viewDidLoad
058.{
059.    [super viewDidLoad];
060.    {
061.        [super viewDidLoad];
062.        tableInfo = [NSArray arrayWithObjects:@"ดอยอินทนนท์",@"กิ่วแม่ปาน",@"น้ำตกแม่กลาง",@"น้ำตกวชิรธาร",
063.                     @"สถานีเกษตรหลวง",@"ถ้ำบรินจินดา",@"น้ำตกแม่ยะ",@"ออบหลวง",@"ออบหลวง",@"ออบหลวง",nil];
064.         
065.         
066.        imageinfo = [NSArray arrayWithObjects:@"moutain2.png",@"moutain2.png",@"moutain2.png",@"moutain2.png",
067.                    @"moutain2.png",@"moutain2.png",@"moutain2.png",@"moutain2.png",@"moutain2.png",@"moutain2.png",nil];
068.         
069.         
070.        content = [NSArray arrayWithObjects:@"ข้อมูลดอยอิน",@"ข้อมูลกิ่ว",@"ข้อมูลน้ำตก",@"ข้อมูลน้ำตก",@"ข้อมูลเกษตร",@"ข้อมูลถ้ำ",@"ข้อมูลแม่ยะ",@"ข้อมูลออบหลวง" ,@"ข้อมูลออบหลวง" ,@"ข้อมูลออบหลวง" ,nil];
071.         
072.        infoArray[0] = [NSArray arrayWithObjects:@"ดอยอินทนนท์",@"กิ่วแม่ปาน",@"น้ำตกแม่กลาง",@"น้ำตกวชิรธาร",
073.                        @"สถานีเกษตรหลวง",@"ถ้ำบรินจินดา",@"น้ำตกแม่ยะ",@"ออบหลวง",@"ออบหลวง",nil];
074.         
075.        infoArray[1] = [NSArray arrayWithObjects:@"ร้านA",@"ร้านB",nil];
076.         
077.        infoArray[2] = [NSArray arrayWithObjects:@"เซA",@"เซB",nil];
078.         
079.        infoArray[3] = [NSArray arrayWithObjects:@"gasA",@"gasB",nil];
080.         
081.        infoArray[4] = [NSArray arrayWithObjects:@"busA",@"busB",nil];
082.         
083.        infoArray[5] = [NSArray arrayWithObjects:@"policeA",@"policeB",nil];
084.         
085.        infoArray[6] = [NSArray arrayWithObjects:@"bankA",@"bankB",nil];
086.         
087.        infoArray[7] = [NSArray arrayWithObjects:@"fesA",@"fesB",nil];
088.         
089.        tableInfo = infoArray[infoRow];
090.        NSLog(@"row : %d",infoRow);
091.        [self GetTableDataFromWeb];
092.             
093.    }
094.    // Do any additional setup after loading the view.
095.}
096. 
097.- (void)didReceiveMemoryWarning
098.{
099.    [super didReceiveMemoryWarning];
100.    // Dispose of any resources that can be recreated.
101.}
102.- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
103.    return [tableInfo count];
104.     
105.} //ตาราง2**
106. 
107. 
108. 
109.- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
110.     
111.    static NSString *simpleTableIdentifier =@"Info";
112.    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
113.    if(cell == nil){
114.        cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
115.               simpleTableIdentifier];
116.    }
117.    cell.textLabel.text = [tableInfo objectAtIndex:indexPath.row];
118.    cell.imageView.image =[UIImage imageNamed:[imageinfo objectAtIndex:indexPath.row]];
119.    //รูป
120.    return cell;
121.}
122. 
123.-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
124.    if([segue.identifier isEqualToString:@"showDetail"]){
125.        NSIndexPath *indexPath = [self.sendDataTable indexPathForSelectedRow];
126.        
127.        InfoViewController *destViewController = segue.destinationViewController;
128.        destViewController.infoFRow = idArray[indexPath.row];
129.        destViewController.dataName = [tableInfo objectAtIndex:indexPath.row];
130.        destViewController.dataText = [content objectAtIndex:indexPath.row];
131.        NSLog(@"rows ddd : %d",destViewController.infoFRow);
132.         
133.        destViewController.hidesBottomBarWhenPushed = YES;
134.         
135.    }
136.     
137.}




เวลาเพิ่มข้อมูลลงฐานข้อมูลมาก ๆ จะ error ต้องคอยมาเพิ่มโค้ดตรงที่ tableinfo และ imageingo ตลอด
มีวิธืเซตให้รับค่าตามฐานข้อมูลเลยได้ไหมคะ



Tag : Mobile, iOS, Mobile



ประวัติการแก้ไข
2014-09-23 20:00:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-09-23 19:58:44 By : pmars View : 1133 Reply : 6
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

Quote:
return [tableInfo count];


เข้าใจว่าตรง count มันทำงานไม่ถูกน่ะครับ เช่น index มีแแค่ 5 แต่ไปเรียกมัน 6 ประมาณนี้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-24 09:57:16 By : mr.win
 

 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2014-09-24 09:57:16
รายละเอียดของการตอบ ::

ลองเปลี่ยนแล้วก็ยังไม่ได้อยู่ดีคะ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-24 16:41:48 By : pmars
 

 

No. 3



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

คุณคงจะต้อง Debug ดูแล้วครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-24 16:48:14 By : mr.win
 

 

No. 4



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



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


คำถาม คือ เวลาเพิ่มข้อมูลลงฐานข้อมูลมาก ๆ จะ error ต้องคอยมาเพิ่มโค้ดตรงที่ tableinfo และ imageingo ตลอด
มีวิธืเซตให้รับค่าตามฐานข้อมูลเลยได้ไหมคะ

แต่ tableInfo = [NSArray arrayWithObjects:@"ดอยอินทนนท์",@"กิ่วแม่ปาน",@"น้ำตกแม่กลาง",@"น้ำตกวชิรธาร",
@"สถานีเกษตรหลวง",@"ถ้ำบรินจินดา",@"น้ำตกแม่ยะ",@"ออบหลวง",@"ออบหลวง",@"ออบหลวง",nil];

hard code ไว้นิครับ หรือผมไม่เข้าใจคำถาม

ถ้าจะให้ tableInfo ใช้ข้อมูลจากฐาน

ก็ควรจะเป็น tableInfo = get items from db;

แบบนี้หรือป่าวคับ

และที่ว่ามาก นี่มากขนาดไหน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-25 16:37:25 By : j4kkapongz
 

 

No. 5



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



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


ตอบความคิดเห็นที่ : 4 เขียนโดย : j4kkapongz เมื่อวันที่ 2014-09-25 16:37:25
รายละเอียดของการตอบ ::
คือแบบนี้นะคะ ถ้าไม่ได้เชื่อมต่อกับอินเตอร์เนต จะแสดงข้อมูล
ตามนี้
tableInfo = [NSArray arrayWithObjects:@"ดอยอินทนนท์",@"กิ่วแม่ปาน",@"น้ำตกแม่กลาง",@"น้ำตกวชิรธาร",
@"สถานีเกษตรหลวง",@"ถ้ำบรินจินดา",@"น้ำตกแม่ยะ",@"ออบหลวง",@"ออบหลวง",@"ออบหลวง",nil]; = 10 แถว

แต่เมื่อดึงข้อมูลมาจากฐานข้อมูลมาแสดง ก็ต้องใส่ข้อมูลได้แค่ 10 เท่านั้น (จากจำนวนข้างบน) หากต้องการข้อมูลมากกว่า 10 ก็ต้องคอยมาเพิ่มตรง tableInfo เรื่อยๆ แบบนี้นะคะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-25 16:53:08 By : pmars
 

 

No. 6



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



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


คือจะให้แสดงครั้งละ 10 ใช่ไหมคับ

แต่มันคงจะควบคุมได้ยาก โดยปกติแล้ว

แอพส่วนใหญ่จะจำกัดการแสดงผลครั้งแรก

และครั้งต่อไปจะโหลดมาเพิ่มเรือยๆ

เป็น view more ผลรวมของ items ทั้งหมดก็จะถูกเพิ่มขึ้น

ไม่ได้คงที่ ที่ 10 เพราะฉะนั้น อาจจะต้องลองหาโค้ดเกี่ยวกับ

load more for uitableview มีตัวอย่างเยอะเลยคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-09-26 14:13:30 By : j4kkapongz
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS รบกวนดูโค้ดให้หน่อยคะ เกี่ยวกับการรับค่าจากฐานข้อมูล
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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