all,
I got most of my app done... major problems worked out down to 2 problems but the first one is kicking my rear end all over the place.
I am trying to get a tableview to populate with JSON data and can get the screen to give me the table with the keyboard (which is a whole another problem) but I can't get it to populate the screen with my json data so that I can move on the didselectrow process for the next view controller because I can't get the screen to count my array and then populate it with the data that I need it to in order to move on. I have done several different tutorials on youtube and can get them all to work now I am just trying to put the pieces together in order to make my app work the way that I need / want it to in order to move on.
DevicetableView.h
DeviceTableView.m
I finally got the system to pass the variables from one controller to the next and I appreciate all the help that you guys gave me on that,so that now works so that I can build my json URL string properly with auth but this me and my partner have been beating our heads against the wall and running in circles just confused.
thanks in advance
RON
I got most of my app done... major problems worked out down to 2 problems but the first one is kicking my rear end all over the place.
I am trying to get a tableview to populate with JSON data and can get the screen to give me the table with the keyboard (which is a whole another problem) but I can't get it to populate the screen with my json data so that I can move on the didselectrow process for the next view controller because I can't get the screen to count my array and then populate it with the data that I need it to in order to move on. I have done several different tutorials on youtube and can get them all to work now I am just trying to put the pieces together in order to make my app work the way that I need / want it to in order to move on.
DevicetableView.h
Code:
#import "ViewController.h"
@interface DeviceTableView : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
UITextField *username;
UITextField *password;
NSMutableArray *anArray;
NSArray *anArray2;
}
@property (retain, nonatomic) IBOutlet UILabel *loginusername;
@property (retain, nonatomic) IBOutlet UILabel *loginpassword;
@property (retain, nonatomic) IBOutlet UITableView *tableview;
@property (strong, nonatomic) IBOutlet UITableView *myTable;
@property (retain, nonatomic) IBOutlet UITextField *username;
@property (retain, nonatomic) IBOutlet UITextField *password;
@property (retain, nonatomic) NSError *localError;
@property (retain, nonatomic) NSDictionary *myConvertedJSONData;
@property (retain, nonatomic) NSArray *anArray2;
@property (retain, nonatomic) NSArray *data3;
@property (retain, nonatomic) NSData *datajson;
@end
DeviceTableView.m
Code:
#import "DeviceTableView.h"
@interface DetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
@implementation DeviceTableView
@synthesize loginpassword, loginusername;
@synthesize username, password;
@synthesize myTable;
@synthesize anArray2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
loginpassword.text = password.text;
loginusername.text = username.text;
NSLog(@"loginpassword = %@", loginpassword);
NSLog(@"loginusername = %@", loginusername);
NSString *url = [NSString stringWithFormat:@"http://a1.php?Fone=%@&pincode=%@&edit=Register", loginusername.text, loginpassword.text];
NSLog(@"string = %@", url);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString : url]];
NSString *strResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"string result = %@", strResult);
NSData *datajson = [strResult dataUsingEncoding: NSUTF8StringEncoding];
id my2ConvertedJSONData = [NSJSONSerialization JSONObjectWithData : datajson options: NSJSONReadingMutableContainers error:&_localError];
NSArray *anArray = my2ConvertedJSONData;
if ([my2ConvertedJSONData isKindOfClass:[NSArray class]])
{
NSArray *anArray = my2ConvertedJSONData;
NSLog(@"ARRAY count: %i", [anArray count]);
if ([[anArray objectAtIndex: 0] isKindOfClass:[NSDictionary class]]) NSLog(@"Yep, dictionary inside of an array!");
NSLog(@"Array dict index 0: %@", [anArray objectAtIndex: 0]);
NSLog(@"anArray = %@", anArray);
NSArray * anArray2 = [[NSArray alloc] initWithArray:anArray copyItems:YES];
NSLog(@"anarray2 count = %i", [anArray2 count]);
NSLog(@"anarray2 = %@", anArray2);
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"anarray 2 in the tableview method = %@", anArray2);
// tried several different items here to get from anArray to anArray2 in order to create the counter and each time the nslog comes up with 0 or null//
NSLog(@"anarray counter = %u", [anArray2 count]);
return [anArray2 count];
[tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[anArray2 objectAtIndex:indexPath.row] objectForKey:@"dname"];
cell.detailTextLabel.text = [[anArray2 objectAtIndex:indexPath.row] objectForKey:@"dlloc"];
NSLog(@"%@", cell);
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewDidUnload {
[self setUsername:nil];
[self setPassword:nil];
[self setLoginusername:nil];
[self setLoginpassword:nil];
[self setTableview:nil];
[super viewDidUnload];
}
@end
I finally got the system to pass the variables from one controller to the next and I appreciate all the help that you guys gave me on that,so that now works so that I can build my json URL string properly with auth but this me and my partner have been beating our heads against the wall and running in circles just confused.
thanks in advance
RON