Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Data not showing up in tableview

Ok so I am thinking this might be a problem in IB but I figured I would post the code and at the very least it might help someone else out doing an asynchronous request or using NSDictionary

ViewController.h
#import <UIKit/UIKit.h>
#import \"ASIHTTPRequest.h\"
#import \"ASIFormDataRequest.h\"
#import \"AppDelegate.h\"

@interface ViewController : UIViewController
{
NSMutableArray *photoTitles;

}
@property (nonatomic, strong) NSMutableArray *photoTitles;

@end


ViewController.m
#import \"ViewController.h\"
#import \"SBJson.h\"

@implementation ViewController
@synthesize photoTitles;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
// [self setupArray];
[super viewDidLoad];
photoTitles = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:@\"http://localhost/test.php\"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];

}
- (void)requestFinished:(ASIFormDataRequest *)request
{

NSString *responseString = [request responseString];

NSDictionary *dictionary = [responseString JSONValue];
NSArray *photos = [[dictionary objectForKey:@\"photos\"] objectForKey:@\"photo\"];

for (NSDictionary *photo in photos) {
NSString *title = [photo objectForKey:@\"title\"];
[photoTitles addObject:title];


}


// Use when fetching text data

// Use when fetching binary data
NSData *responseData = [request responseData];
NSLog(@\"Data: %@\", responseData);





}
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [photoTitles count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @\"SimpleTableIdentifier\";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier: SimpleTableIdentifier];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [photoTitles objectAtIndex:row];

return cell;

}


- (void)requestFailed:(ASIFormDataRequest *)request
{
NSError *error = [request error];
NSLog(@\"error: %@\", error);

}






- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end


This does not have any errors except the data from the photoTitles mutable array does not show up in the table view. Any help would be great.
Post edited by wright0768 on

Replies

Sign In or Register to comment.