1

I am stucked in this problem for many hours and have n't found any solution on SO...

I have got a table as a subview in UIViewController. When view loads, all datasource methods are called for tableview, but as I receive data from server and call [someTable reloadData], none of the data source methods are called. I have confirmed through breakpoints that my array do contains 100 objects. Also both delegate and datasource are bind to File owner in IB.

What can be possibly missing ? Please help me... Thanks :(

OutLogController.h

@interface OutLogController : UIViewController<UITableViewDataSource,UITableViewDelegate,ASIHTTPRequestDelegate>
{
    NSMutableArray *outstandingKeys;

}
@property (strong, nonatomic) IBOutlet UITableView *someTable;

@end

OutLogController.m

@interface OutLogController ()

@end

@implementation OutLogController

@synthesize someTable;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    outstandingKeys = [[NSMutableArray alloc] init];
    someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    someTable.rowHeight = 85;
    [self retrieveOutstandingLogFromServer];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return outstandingKeys.count;
}

- (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];

    }

    // Configure the cell...
    LogUnit *unit = [outstandingKeys objectAtIndex:indexPath.row];

     cell.textLabel.text = unit.symbol;

    return cell;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 85;
}

-(void) requestFinished:(ASIHTTPRequest *)request
{
    NSLog(@"%@",request.responseString);
    NSArray *list = [request.responseString JSONValue];//contains 100 objects

    for (int i = 0; i < list.count; i++) {

        NSArray *singleTrade = [[list objectAtIndex:i] JSONValue];

        LogUnit *unit = [[LogUnit alloc] init];

        unit.symbol = [singleTrade objectAtIndex:0];
        unit.type = [singleTrade objectAtIndex:1];
        unit.price = [singleTrade objectAtIndex:2];
        unit.remaining = [singleTrade objectAtIndex:3];
        unit.order = [singleTrade objectAtIndex:4];
        unit.time = [singleTrade objectAtIndex:5];

        [outstandingKeys addObject:unit];

    }

    if(outstandingKeys.count > 0)
    {
        [someTable reloadData];//does reload table

    }

}

EDIT

After removing line:

someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

Datasource methods are called except cellForRowAtIndexPath and table disappears from view since this method is not called. Any idea why it can't get called?

Note: I have confirmed that I have count = 100 after response from server.

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90
NightFury
  • 13,436
  • 6
  • 71
  • 120
  • someTable is a IBoutlet so you should connect it to the table in the XIB have you connected it – Divyam shukla Jul 11 '13 at 10:32
  • someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; – Divyam shukla Jul 11 '13 at 11:11
  • You've probably already resolved this, but this answer helped me solve this issue: http://stackoverflow.com/questions/4163579/how-to-detect-the-end-of-loading-of-uitableview – Tum Nov 17 '13 at 12:50

4 Answers4

0
someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

You have already bind your UITableView from nib/storyboard. In this case you did not have to alloc again the tableview. Removing this line will do the work

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
0

someTable = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

You create new tableView and it doesn't add to current view.

Misha Vyrko
  • 992
  • 6
  • 14
0

check your outstandingKeys Count may it zero count

kirti Chavda
  • 3,029
  • 2
  • 17
  • 29
0

Try to reload data by performing it on main thread..

dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableRating reloadData];
    });

This will solve your problem. Happy Coding..

Ritu pal
  • 306
  • 2
  • 11