Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-21-2011, 05:59 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 1
hazelnut is on a distinguished road
Default self.tableView reloadData breaks it

i hope somebody can help me. i want to fetch a json file and update a tableview with the data. that's my .h

PHP Code:
@interface FirstViewController UITableViewController {
    
UITableView *tableView;    
    
NSDictionary *listData;    
    
NSMutableData *responseData;
}
@
property (nonatomicretainNSDictionary *listData;
@
property (nonatomicretainNSMutableData *responseData;
@
property (nonatomicretainIBOutlet UITableView *tableView
and my .m

PHP Code:
@synthesize listData;
@
synthesize responseData;
@
synthesize tableView;

- (
void)viewDidLoad 
{
    
self.listData nil;

    
// load external data    
    
responseData = [[NSMutableData dataretain];
    
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://JSON_URL"]];
    [[
NSURLConnection allocinitWithRequest:request delegate:self];
    
    [
super viewDidLoad];
}
- (
void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [
responseData setLength:0];
}
- (
void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [
responseData appendData:data];
}
- (
void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
NSLog(@"Connection failed: %@", [error description]);
}
- (
void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [
connection release];
    
    
NSError *error nil;
    
NSDictionary *dictionary = [[CJSONDeserializer deserializerdeserializeAsDictionary:responseData error:&error];
    
    
self.listData dictionary;
    
    [
self.tableView reloadData]; // <--------- breaks it, but why??
}

- (
NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 
1;
}
- (
NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [
self.listData count];
}
- (
UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static 
NSString *CellIdentifier = @"CustomCell";
    
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (
cell == nil) {
        
        
NSArray *topLevelObjects = [[NSBundle mainBundleloadNibNamed:@"CustomCell" owner:self options:nil];
        
        for (
id currentObject in topLevelObjects){
            if ([
currentObject isKindOfClass:[UITableViewCell class]]){
                
cell =  (CustomCell *) currentObject;
                break;
            }
        }
    }
    
    return 
cell;
}
- (
void)didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning];
}
- (
void)dealloc {
    [
responseData release];
    [
listData release];
    [
super dealloc];

after fetching the json data (connectionDidFinishLoading) the [self.tableView reloadData] breaks the app. but why? i've read in so many posts that that is the way the reload a tableview (?)

thanks for any help
hazelnut is offline   Reply With Quote
Reply

Bookmarks

Tags
reloaddata, tableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 325
8 members and 317 guests
chemistry, Dnnake, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0