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 - Code JSON ใช้ดึงฐานข้อมูลจากเซิฟเว่อร์ แล้วโชว์เป็น List รายงาน ที่จะส่งลิ้งไปหน้ารายละเอียด



 

iOS - Code JSON ใช้ดึงฐานข้อมูลจากเซิฟเว่อร์ แล้วโชว์เป็น List รายงาน ที่จะส่งลิ้งไปหน้ารายละเอียด

 



Topic : 097525



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



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




ช้ โค้ด JSON ดึงข้อมูลมาจากฐานข้อมูล โดยการโชว์ เป็น Cell แต่จะให้ Cell ถูกลิ้งไปอีกหน้า ที่จะโชว์รายละเอียดของข้อมูล นี้จะต้องทำยางไงคับ

เหมือน List ข่าว แล้ว เข้าไปดู รายละเอียดได้อะคับ

โค้ด JSON ดึงฐานข้อมูลมาได้แล้ว แต่จะลิ้งไปอีกหน้า ยางทำไม่ได้คับ



Tag : Mobile, MySQL, iOS







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-07-08 11:03:21 By : yimkrub View : 1515 Reply : 24
 

 

No. 1



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

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

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

Master-Detail ครับ ไม่ยาก



iOS/iPhone Storyboard and TableView Master-Detail (Objective-C,iPhone,iPad)


Apply เอาครับ ไม่ยาก แค่เพิ่มตรง Master , Detail ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-08 11:20:38 By : mr.win
 


 

No. 2



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



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


1

แก้ยังไงคับ เออเร่อ tableView
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-10 14:44:21 By : yimkrub
 

 

No. 3



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

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

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

ตัวแปรของ TableView ชื่ออะไรครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-10 14:49:44 By : mr.win
 


 

No. 4



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



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


IBOutlet UITableView *myTable;
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-10 15:13:46 By : yimkrub
 


 

No. 5



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



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


ยังเออเร่อ อยู่เลยคับ ลอง mytable ไปแล้วก็ติดอยู่อะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-18 21:13:11 By : yimkrub
 


 

No. 6



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



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


เงียบกิบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-25 11:25:39 By : yimkrub
 


 

No. 7



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



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


ลอง post .h และ .m ดูหน่อยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-25 11:34:06 By : LindyFralin
 


 

No. 8



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



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


.h
#import <UIKit/UIKit.h>

@interface WatluangViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
    IBOutlet UITableView *myTable;
}
@property (nonatomic, assign) NSMutableData *receivedData;
@end

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-27 12:25:11 By : yimkrub
 


 

No. 9



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



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


.m

Code (Objective-C)
#import "WatluangViewController.h"

#import "DetailWatluangViewController.h"

@interface WatluangViewController ()
@end

@implementation WatluangViewController
{
    NSMutableArray *myObject;
    
    // A dictionary object
    NSDictionary *dict;
    
    // Define keys
    NSString *TempleID;
    NSString *TypeID;
    NSString *TempleName;
    NSString *TempleDescription;
    NSString *Latitude;
    NSString *Longitude;
    NSString *TemplePic;
    
    UIAlertView *loading;
}
@synthesize receivedData;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // Define keys
    TempleID = @"TempleID";
    TypeID = @"TypeID";
    TempleName = @"TempleName";
    TempleDescription = @"TempleDescription";
    Latitude = @"Latitude";
    Longitude = @"Longitude";
    TemplePic = @"TemplePic";
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    // Create array to hold dictionaries
    myObject = [[NSMutableArray alloc] init];
    
    
    NSURLRequest *theRequest =
    [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.waiphainayutthaya.com/Watluang.php"]
                     cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                 timeoutInterval:10.0];
    
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if (theConnection) {
        self.receivedData = [[NSMutableData data] retain];
       // UIAlertView *connectMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection "
       //     message:@"คอนเน็กได้แล้ว" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
       // [connectMessage show];
       // [connectMessage release];
    } else {
		UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"คอนเน็กล้มเหลว"  delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
		[connectFailMessage show];
		[connectFailMessage release];
    }
    // Loading Show Alert View...
    loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [loading addSubview:progress];
    [progress startAnimating];
    [progress release];
    [loading show];
    
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
    [connection release];
    [receivedData release];
    
    // inform the user
    UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"didFailWithError"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [didFailWithErrorMessage show];
    [didFailWithErrorMessage release];
	
    //inform the user
    NSLog(@"Connection failed! Error - %@", [error localizedDescription]);
    
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    
    if(receivedData)
    {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        [loading dismissWithClickedButtonIndex:0 animated:YES];
        
        id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
        
        // values in foreach loop
        for (NSDictionary *dataDict in jsonObjects) {
            NSString *strTempleID = [dataDict objectForKey:@"TempleID"];
            NSString *strTypeID = [dataDict objectForKey:@"TypeID"];
            NSString *strTempleName = [dataDict objectForKey:@"TempleName"];
            NSString *strTempleDescription = [dataDict objectForKey:@"TempleDescription"];
            NSString *strLatitude = [dataDict objectForKey:@"Latitude"];
            NSString *strLongitude = [dataDict objectForKey:@"Longitude"];
            NSString *strTemplePic = [dataDict objectForKey:@"TemplePic"];
            
            dict = [NSDictionary dictionaryWithObjectsAndKeys:
                    strTempleID, TempleID,
                    strTypeID, TypeID,
                    strTempleName, TempleName,
                    strTempleDescription, TempleDescription,
                    strLatitude, Latitude,
                    strLongitude, Longitude,
                    strTemplePic, TemplePic,
                    nil];
            [myObject addObject:dict];
        }
        
        [myTable reloadData];
    }
    
    
    // release the connection, and the data object
    [connection release];
    [receivedData release];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    int nbCount = [myObject count];
    if (nbCount == 0)
        return 1;
    else
        return [myObject count];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    int nbCount = [myObject count];
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        // Use the default cell style.
        cell = [[[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
                                       reuseIdentifier : CellIdentifier] autorelease];
           }
    
           if (nbCount ==0){
               cell.textLabel.text = @"Loading Data";
           }
           else
           {
               
        NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
        
        NSURL *url = [NSURL URLWithString:[tmpDict objectForKey:TemplePic]];
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        cell.imageView.image = img;
        
        cell.textLabel.text = [tmpDict objectForKey:TempleName];
        cell.detailTextLabel.text= [tmpDict objectForKey:TempleDescription];
               
     /*   UIAlertView *nsDict = [[UIAlertView alloc] initWithTitle:@"NSURLConnection "
            message:@"nsDict" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
               [nsDict show];
               [nsDict release]; */
           }
               return cell;
    
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        
        NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
        
        [[segue destinationViewController] setTemplePicItem:[tmpDict objectForKey:TemplePic]];
        [[segue destinationViewController] setTempleNameItem:[tmpDict objectForKey:TempleName]];
        [[segue destinationViewController] setTempleDescriptionItem:[tmpDict objectForKey:TempleDescription]];
    }
    
}

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

- (void)dealloc {
    [myTable release];
    [super dealloc];
}
@end

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-29 12:00:31 By : yimkrub
 


 

No. 10



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



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


ออเร่อ ตรงบรรทัด 206 อะคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-29 16:44:10 By : yimkrub
 


 

No. 11



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



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


รันไม่ออก เลยคับ ลองแล้วลองอีก
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-01 12:13:13 By : yimkrub
 


 

No. 12



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

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

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


ตอนนี้ปัญหาคือยังไงนะครับ

1. แสดงข้อมูลจาก Json ใน table view ได้แล้วใช้เปล่า
2. เมื่อคลิกที่แต่ละ row จะให้ไปอีกหน้าหนึ่งใช้เปล่า

ติดปัญหาข้อ 2 ใช้เปล่าครับ เหมือนพี่บทความพี่วินจะมีแนะสอนอยู่นะ เดียวผมไปเปิด macbook ก่อนละกันจะได้ช่วยทดสอบให้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-01 22:12:25 By : somparn
 


 

No. 13



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

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

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


มี message Error ให้ดูครับเปล่า เหมือนว่ามันหาตัวแปรไม่เจอหรือยังไม่ได้ เชื่อมโยง object ในหน้า storyboad อ่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-01 23:25:14 By : somparn
 


 

No. 14



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

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

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


ไม่ทราบว่าตอนนี้เป็นยังไงครับ ได้หรือยังครับ

พอดีผมได้เขียนแบบไม่ใช้ storyborad ไว้ code สั่นๆครับไม่เยอะ ถ้าไม่ได้ยังไงบอกบอกนะครับจะได้ช่วยกันหาวิธีแก้ไข
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-03 23:14:16 By : somparn
 


 

No. 15



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

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

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

อันที่จริงในตัวอย่างมันก็มีให้ดูครับ เพียงแค่ค่อย ๆ Apply ครับ จะได้ไม่งง และ หา Error ได้ง่ายครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-03 23:16:44 By : mr.win
 


 

No. 16



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



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


ติด ข้อ 2 ครับ มันไม่ส่งค่าไปอีกหน้า ส่วนข้อ 1 มันรัน จาก JSON มาโชว์ได้แล้ว ครับ

Code
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row]; [[segue destinationViewController] setTemplePicItem:[tmpDict objectForKey:TemplePic]]; [[segue destinationViewController] setTempleNameItem:[tmpDict objectForKey:TempleName]]; [[segue destinationViewController] setTempleDescriptionItem:[tmpDict objectForKey:TempleDescription]]; } }


มันเออเร่อตรงนี้ อะคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-04 20:03:48 By : yimkrub
 


 

No. 17



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



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




ตรงนั้นลองเปลี่ยน เป็น myTable ก็เออเร่อ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-04 20:53:34 By : yimkrub
 


 

No. 18



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

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

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


มันหา tableView ไม่เจอครับ ไม่ทราบว่าได้เชื่อม Class ตามหน้านี้หรือยังครับ
https://www.thaicreate.com/mobile/ios-iphone-storyboard-passing-data-between-view.html
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-06 21:29:51 By : somparn
 


 

No. 19



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



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


ขอบคุณครับจะลองแก้ไข้ ดู
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-06 21:47:04 By : yimkrub
 


 

No. 20

Guest


มาช้าไปหรือป่าวผม

ชื่อตัวแปรไม่ตรงครับ

ของคุณประกาศเป็น myTable ต้อง self.myTable ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-09 17:02:58 By : ปลา
 


 

No. 21



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



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


self.myTable ลองละคับ มัน เออเร่อ ให้ใช้ self->myTable ก็เออเร่อ อะคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-14 14:45:19 By : yimkrub
 


 

No. 22



โพสกระทู้ ( 1,579 )
บทความ ( 3 )

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

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


มันใช้คำสั่ง self->myTable แบบนี้ได้หรือครับ (ผมไม่รู้เลยถามดู)

ตกลงนี้ยังไม่ได้ใช้เปล่าครับ
ค่ำนี้ผมขอยืม URL ของคุณ Yimkrub หน่อยนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-20 15:03:11 By : somparn
 


 

No. 23



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



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


ได้ละครับบบ ขอบคุณมาก ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-22 22:52:42 By : yimkrub
 


 

No. 24



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



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


มีอีกเรื่องที่จะถามคับ คือจะเอา ตัวแปร ลิ้งไป google map ใส่ช่อง textbox ในค้นหาสถานที่ ต้องทำยังไงครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-22 22:54:29 By : yimkrub
 

   

ค้นหาข้อมูล


   
 

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