Sunday, 8 September 2013

Parse, UITableView and reloaddata

Parse, UITableView and reloaddata

Im sitting on this almost 4 days and I can't find the problem (already
searched google a lot and try everything but nothing helped). so I have
this table view I created on my storyboard. everything is connect BUT when
I run my code: first all the tableview method runs but since array still
nil nothing happened. than after my array got all the data and code says
[tableView1 reloadData]; nothing happened and Im not getting to the
tableView methods... (I tried to locate the reloadData in many places in
my code and nothing worked).
maybe its really stupid mistake but im really desperate
-(void)viewDidLoad{ [super viewDidLoad]; self.tableView1.dataSource=self;
self.tableView1.delegate=self; self.tripNamesList = [[NSMutableArray
alloc] init];
[self GetTripsList];
PFQuery *query = [PFQuery queryWithClassName:@"Trips"];
NSString *userID = user.objectId;
[query whereKey:@"User_Created_ID" equalTo:userID];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError
*error) {
if (!error) {
NSLog(@"Successfully retrieved %d trips.", objects.count);
[self.tripNamesList addObjectsFromArray:objects];
NSLog(@"%@", tripNamesList);
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
[self.tripNamesList addObject:object ];
}
[tableView1 reloadData];
}
else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.tripNamesList count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Calling 1222rrgdfghgfhdgfdfgfdgdfgd on %@", tableView);
static NSString *CellIdentifier = @"TripCell";
UITableViewCell *cell = [self.tableView1
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] ;
}
PFObject *obj2 = [self.tripNamesList objectAtIndex:indexPath.row];
PFQuery *query = [PFQuery queryWithClassName:@"Trips"];
PFObject *searchedItems = [query getObjectWithId:obj2.objectId];
NSString *tempTripName = [searchedItems objectForKey:@"Trip_Name"];
cell.textLabel.text = tempTripName;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[self.tableView1 reloadData];
return cell;
}
@end

No comments:

Post a Comment