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



 

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 : 1235 Reply : 5
 

 

No. 1



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

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

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



ให้เดา น่าจะไมไ่ด้เชื่อม Delegate ตัว Method หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-16 19:48:08 By : mr.win
 


 

No. 2

Guest


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

ss


ไฟล์ .m
Code
//
//  ViewController.m
//  getDataFromServer
//
//  Created by Weerachai on 12/10/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import "showViewController.h"

@interface showViewController ()
{
    NSMutableArray *myObject;
    
    // A dictionary object
    NSDictionary *dict;
    
    // Define keys
    NSString *device_id;
    NSString *ip_address;
    NSString *mac_address;
    NSMutableData *receivedData;
    UIAlertView *loading;
}

@end

@implementation showViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // Define keys
    device_id = @"device_id";
    ip_address = @"ip_address";
    mac_address = @"mac_address";
    
    // Create array to hold dictionaries
    myObject = [[NSMutableArray alloc] init];
    
    
    NSURLRequest *theRequest =
    [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://202.44.47.47/mac/show.php"]
                     cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                 timeoutInterval:10.0];
    
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    
    // Loading...
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    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];
    [loading show];
    
    if (theConnection) {
        receivedData = nil;
    } else {
        UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad"  delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [connectFailMessage show];
        
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    receivedData = [[NSMutableData alloc] init];
}

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

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

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [loading dismissWithClickedButtonIndex:0 animated:YES];
    
    if(receivedData)
    {
        //NSLog(@"%@",receivedData);
        //NSString *dataString = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
        //NSLog(@" abc = %@",dataString);
        
        id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
        
        // values in foreach loop
        for (NSDictionary *dataDict in jsonObjects) {
            NSString *strdevice_id = [dataDict objectForKey:@"Device_id"];
            NSString *strip_address = [dataDict objectForKey:@"IP_Address"];
            NSString *strmac_address = [dataDict objectForKey:@"MAC_Address"];
            
            dict = [NSDictionary dictionaryWithObjectsAndKeys:
                    strdevice_id, device_id,
                    strip_address, ip_address,
                    strmac_address, mac_address,
                    nil];
            [myObject addObject:dict];
        }
        
        [myTable reloadData];
    }
    
    // release the connection, and the data object
    
}

- (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
{
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        // Use the default cell style.
        cell = [[UITableViewCell alloc] initWithStyle : UITableViewCellStyleSubtitle
                                       reuseIdentifier : CellIdentifier];
    }
    
    int nbCount = [myObject count];
    if (nbCount ==0)
        cell.textLabel.text = @"Loading Data";
    else
    {
        NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
        
        // MemberID
        NSMutableString *text;
        text = [NSMutableString stringWithFormat:@"Device ID : %@",[tmpDict objectForKey:device_id]];
        
        // Name & Tel
        NSMutableString *detail;
        detail = [NSMutableString stringWithFormat:@"MAC : %@ , IP : %@"
                  ,[tmpDict objectForKey:mac_address]
                  ,[tmpDict objectForKey:ip_address]];
        
        cell.textLabel.text = text;
        cell.detailTextLabel.text= detail;
        
        //[tmpDict objectForKey:memberid]
        //[tmpDict objectForKey:name]
        //[tmpDict objectForKey:tel]
    }
    return cell;
}


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



ไฟล.h



Code
//
//  showViewController.h
//  auten
//
//  Created by Peat-Mac on 11/14/2557 BE.
//  Copyright (c) 2557 Saringkhan Vungsin. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface showViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
    IBOutlet UITableView *myTable;
}
@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,058 )
บทความ ( 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







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 อัตราราคา คลิกที่นี่