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 - Run UITableView แล้วไม่ขึ้นข้อมูลอะไรออกมาเลย ช่วยด้วยครับ TT


[Mobile] iOS - Run UITableView แล้วไม่ขึ้นข้อมูลอะไรออกมาเลย ช่วยด้วยครับ TT

 
Topic : 112597



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



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



https://www.thaicreate.com/mobile/ios-iphone-nsurlconnection-retrieve-data-from-web-server.html

ผมทำตามในเนี้ยอะคับ แล้วพอ รันโปรแกรมออกมา มันไม่แสดงค่าอะไรออกมาให้เห็นเลย ของผมทำใน mainstoryboard ไม่ใช้ .xib



Tag : Mobile, MySQL, iOS, iPad, Mobile

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-11-16 18:20:22 By : peatza130 View : 1371 Reply : 5
 

 

No. 1



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

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

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



ให้เดา น่าจะไมไ่ด้เชื่อม Delegate ตัว Method หรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-16 19:48:08 By : mr.win
 

 

No. 2

Guest


ผมเชื่อม delegate กับ datasource แล้วคับ

ss


ไฟล์ .m
Code
001.//
002.//  ViewController.m
003.//  getDataFromServer
004.//
005.//  Created by Weerachai on 12/10/55 BE.
006.//  Copyright (c) 2555 Weerachai. All rights reserved.
007.//
008. 
009.#import "showViewController.h"
010. 
011.@interface showViewController ()
012.{
013.    NSMutableArray *myObject;
014.     
015.    // A dictionary object
016.    NSDictionary *dict;
017.     
018.    // Define keys
019.    NSString *device_id;
020.    NSString *ip_address;
021.    NSString *mac_address;
022.    NSMutableData *receivedData;
023.    UIAlertView *loading;
024.}
025. 
026.@end
027. 
028.@implementation showViewController
029. 
030.- (void)viewDidLoad
031.{
032.    [super viewDidLoad];
033.    // Do any additional setup after loading the view, typically from a nib.
034.     
035.    // Define keys
036.    device_id = @"device_id";
037.    ip_address = @"ip_address";
038.    mac_address = @"mac_address";
039.     
040.    // Create array to hold dictionaries
041.    myObject = [[NSMutableArray alloc] init];
042.     
043.     
044.    NSURLRequest *theRequest =
045.    [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://202.44.47.47/mac/show.php"]
046.                     cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
047.                 timeoutInterval:10.0];
048.     
049.    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
050.     
051.     
052.    // Loading...
053.    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
054.     
055.    loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
056.    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
057.    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
058.    [loading addSubview:progress];
059.    [progress startAnimating];
060.    [loading show];
061.     
062.    if (theConnection) {
063.        receivedData = nil;
064.    } else {
065.        UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad"  delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
066.        [connectFailMessage show];
067.         
068.    }
069.}
070. 
071.- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
072.{
073.    receivedData = [[NSMutableData alloc] init];
074.}
075. 
076.- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
077.{
078.    sleep(2);
079.    [receivedData appendData:data];
080.}
081. 
082.- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
083.{
084.     
085.     
086.    // inform the user
087.    UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"didFailWithError"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
088.    [didFailWithErrorMessage show];
089.     
090.     
091.    //inform the user
092.    NSLog(@"Connection failed! Error - %@", [error localizedDescription]);
093.     
094.}
095. 
096.- (void)connectionDidFinishLoading:(NSURLConnection *)connection
097.{
098.     
099.    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
100.    [loading dismissWithClickedButtonIndex:0 animated:YES];
101.     
102.    if(receivedData)
103.    {
104.        //NSLog(@"%@",receivedData);
105.        //NSString *dataString = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
106.        //NSLog(@" abc = %@",dataString);
107.         
108.        id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
109.         
110.        // values in foreach loop
111.        for (NSDictionary *dataDict in jsonObjects) {
112.            NSString *strdevice_id = [dataDict objectForKey:@"Device_id"];
113.            NSString *strip_address = [dataDict objectForKey:@"IP_Address"];
114.            NSString *strmac_address = [dataDict objectForKey:@"MAC_Address"];
115.             
116.            dict = [NSDictionary dictionaryWithObjectsAndKeys:
117.                    strdevice_id, device_id,
118.                    strip_address, ip_address,
119.                    strmac_address, mac_address,
120.                    nil];
121.            [myObject addObject:dict];
122.        }
123.         
124.        [myTable reloadData];
125.    }
126.     
127.    // release the connection, and the data object
128.     
129.}
130. 
131.- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
132.{
133.     
134.    int nbCount = [myObject count];
135.    if (nbCount == 0)
136.        return 1;
137.    else
138.        return [myObject count];
139.     
140.}
141. 
142.- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
143.{
144.     
145.    static NSString *CellIdentifier = @"Cell";
146.     
147.    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
148.    if (cell == nil) {
149.        // Use the default cell style.
150.        cell = [[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
151.                                       reuseIdentifier : CellIdentifier];
152.    }
153.     
154.    int nbCount = [myObject count];
155.    if (nbCount ==0)
156.        cell.textLabel.text = @"Loading Data";
157.    else
158.    {
159.        NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
160.         
161.        // MemberID
162.        NSMutableString *text;
163.        text = [NSMutableString stringWithFormat:@"Device ID : %@",[tmpDict objectForKey:device_id]];
164.         
165.        // Name & Tel
166.        NSMutableString *detail;
167.        detail = [NSMutableString stringWithFormat:@"MAC : %@ , IP : %@"
168.                  ,[tmpDict objectForKey:mac_address]
169.                  ,[tmpDict objectForKey:ip_address]];
170.         
171.        cell.textLabel.text = text;
172.        cell.detailTextLabel.text= detail;
173.         
174.        //[tmpDict objectForKey:memberid]
175.        //[tmpDict objectForKey:name]
176.        //[tmpDict objectForKey:tel]
177.    }
178.    return cell;
179.}
180. 
181. 
182.- (void)didReceiveMemoryWarning
183.{
184.    [super didReceiveMemoryWarning];
185.    // Dispose of any resources that can be recreated.
186.}
187.@end



ไฟล.h



Code
01.//
02.//  showViewController.h
03.//  auten
04.//
05.//  Created by Peat-Mac on 11/14/2557 BE.
06.//  Copyright (c) 2557 Saringkhan Vungsin. All rights reserved.
07.//
08. 
09.#import <UIKit/UIKit.h>
10. 
11.@interface showViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
12.{
13.    IBOutlet UITableView *myTable;
14.}
15.@end

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 12:51:19 By : peatza130
 

 

No. 3

Guest


sa

ข้อมูลจาก DB คับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 12:59:03 By : peatza130
 

 

No. 4

Guest


ผม nslog ออกมาดูค่าในแต่ละฟังชัน ฟังชัน
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

เหมือนมันไม่ถุกเรียกใช่งานเลยอะคับ เพราะ ใช่คำสั่ง

NSLog(@"receivedData: %d",nbCount);

มันไม่มีอะไรออกมาเลยแม้แต่ receivedData
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 14:00:51 By : peatza130
 

 

No. 5



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

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

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

มันไม่ถูกเรียกเพราะคุณยังไม่ได้เชื่อม Delegate ตัว Method น่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-18 20:13:49 By : mr.win
 

   

ค้นหาข้อมูล


   
 

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