|
|
|
iOS - ล็อกอินแล้วโชว์ข้อมูล ใน TableView แต่ว่าไม่ขึ้นอะไรเลย ช่วยดูโค้ดให้หน่อยค่ะว่าผิดตรงไหน |
|
|
|
|
|
|
|
ล็อกอินแล้วโชว์ข้อมูล ใน TableView แต่ว่าไม่ขึ้นอะไรเลย ช่วยดูโค้ดให้หน่อยค่ะว่าผิดตรงไหน
Code (Objective-C)
//
// logindetailViewController.m
// Loginapp
//
// Created by Nakornjinda on 3/19/2557 BE.
// Copyright (c) 2557 Nakornjinda. All rights reserved.
//
#import "logindetailViewController.h"
#import "loginViewController.h"
@interface logindetailViewController ()
{
NSMutableArray*myObject;
NSMutableArray *displayObject;
// A Dictionary object
NSDictionary*dict;
//Define keys
NSString*lblStudentID;
NSString*lblIdname;
NSString*lblNamebook;
NSString*lblLNameT;
NSString*lblFNameT;
UIAlertView *loading;
}
@end
@implementation logindetailViewController
@synthesize receivedData;
- (void)viewDidLoad
{
[super viewDidLoad];
//Define Keys
lblStudentID=@"StudentID";
lblIdname=@"Idname";
lblNamebook=@"Namebook";
lblLNameT=@"LNameT";
lblFNameT=@"FNameT";
// Create array to hold dictionaries
myObject = [[NSMutableArray alloc] init];
//Keyword=abc
NSMutableString *post = [NSString stringWithFormat:@"sStudentID =%@",[ self.sStudentID description]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://localhost:8888/app/getUserByMemberID.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSLog(@"lg info post is = %@",post);
NSLog(@"lg info postData is = %@",postData);
NSLog(@"lg info postLength is = %@",postLength);
NSLog(@"lg info url is = %@",url);
NSLog(@"lg info request is = %@",request);
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"Connection = %@",theConnection);
// Show Progress 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];
[progress release];
[loading show];
NSLog(@"progress = %@",progress);
if (theConnection) {
self.receivedData = [[NSMutableData data] retain];
} else {
UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[connectFailMessage show];
[connectFailMessage release];
}
[myTable reloadData];
}
- (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)
{
//NSLog(@"%@",receivedData);
//NSString *dataString = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
//NSLog(@"%@",dataString);
id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
// values in foreach loop
for (NSDictionary *dataDict in jsonObjects) {
NSString *strStudentID = [dataDict objectForKey:@"StudentID"];
NSString *strIdName = [dataDict objectForKey:@"IdName"];
NSString *strNamebook = [dataDict objectForKey:@"Namebook"];
NSString *strLNameT = [dataDict objectForKey:@"LNameT"];
NSString *strFNameT = [dataDict objectForKey:@"FNameT"];
NSLog(@"StudentID = %@",strStudentID);
NSLog(@"Idname = %@",strIdName);
NSLog(@"Namebook = %@",strNamebook);
NSLog(@"FNameT = %@",strFNameT);
NSLog(@"LNameT = %@",strLNameT);
dict = [NSDictionary dictionaryWithObjectsAndKeys:
strStudentID, lblStudentID,
strIdName, lblIdname,
strNamebook, lblNamebook,
strLNameT, lblLNameT,
strFNameT, lblFNameT,
nil];
[myObject addObject:dict];
}
[myTable reloadData];
}
displayObject =[[NSMutableArray alloc] initWithArray:myObject];
// release the connection, and the data object
[connection release];
[receivedData release];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return displayObject.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];
}
NSDictionary *tmpDict = [displayObject objectAtIndex:indexPath.row];
NSString *cellValue;
cellValue = [tmpDict objectForKey:lblStudentID];
NSString* detailbook;
detailbook = [NSString stringWithFormat:@"รหัส%@ , ผู้แต่ง %@, สถานะ %@ "
,[tmpDict objectForKey:lblFNameT]
,[tmpDict objectForKey:lblLNameT]
,[tmpDict objectForKey:lblNamebook]];
cell.textLabel.text = cellValue;
cell.detailTextLabel.text= detailbook;
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[myTable release];
[super dealloc];
}
@end
Tag : Mobile, MySQL, iOS, iPhone, Objective-C, Mac
|
|
|
|
|
|
Date :
2014-03-20 14:47:58 |
By :
fern_105 |
View :
897 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iOS/iPhone Login Username and Password from Web Server (PHP & MySQL)
|
|
|
|
|
Date :
2014-03-21 09:30:33 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|