An array is filled properly but when I try to access to content again, seems that is empty again!! trying to post as many code as necessary. Thanks for help.
I declare appData in .h file:
@interface userViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *appData;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UILabel *status;
IBOutlet UITableView *mainTable;
}
@property (nonatomic, retain) NSArray *appData;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) UILabel *status;
@property (nonatomic, retain) UITableView *mainTable;
- (IBAction) refresca: (id)sender;
- (void)getData: (NSString *)usuari: (NSString *)clau;
@end
in .m file is synthesized and released. appData is properly filled when connection request ends and then, when I reload tableview, when numberOfRowsInSection executed (while loop also in order to test), appData is empty!
- (void)requestFinished:(ASIHTTPRequest *)request {
NSLog(@"%@", [request responseString]);
self.appData = [[request responseString] componentsSeparatedByString: @"#"];
int x =0;
while (x<[appData count] - 1)
{
NSLog(@"Aplicaciones = %@",[appData objectAtIndex: x]);
x = x+1;
}
[activityIndicator stopAnimating];
activityIndicator.hidden = YES;
status.hidden = YES;
mainTable.hidden = NO;
[mainTable reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([appData count] != 0)
{
NSLog(@"Counter = %@",[appData objectAtIndex:0]);
}
return [appData count]-1;
}
A couple of things here.
Your test logging in
numberOfRowswill cause the app to hang if appdata ever has a non-zero count.Are you sure you are getting the the same
appDataobject that you populate inrequestFinished?I suggest using the accessor in numberOfRows as in
[self.appData count]which might sort out the problem.And is there a specific reason you subtract one from the count? As you will lose one element from the array in the tableView that way