Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialglennseplowitz
13,859 PointsApplication crashed when I run it, log in, and select edit.
The application crashes on this line: PFUser *user = [self.allUsers objectAtIndex:indexPath.row]; In the cellForRowAtIndexPath in the EditFriendsTableViewController.m file.
I am using xCode 6.4. I followed the video twice and downloaded the sample files. I made sure I did everything the video told me. I still cannot get this running.
Can anyone help out?
I tried closing the project and opening it again and this didn't help.
6 Answers
glennseplowitz
13,859 PointsGabe,
I have no idea how I got this working. I closed out of xcode. Opened another project in xcode. Closed that out then decided to try and fix my problem. So I re-opened my problem project and it started working. Very weird. Thanks for your help.
Glenn
Anthony Martinez
13,111 PointsPlease post your code or zip your project somewhere so we can see it.
Basically there's something wrong on or about where PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
is called.
glennseplowitz
13,859 PointsI don't know how to zip up my project. Below is the EditFriendsTableViewContoller.m file that has the problem. Thanks.
// EditFriendsTableViewController.m
// Ribbit
//
// Created by Glenn Seplowitz on 8/9/15.
// Copyright (c) 2015 Glenn Seplowitz. All rights reserved.
//
#import "EditFriendsTableViewController.h"
#import <Parse/Parse.h>
@interface EditFriendsTableViewController ()
@end
@implementation EditFriendsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
PFQuery *query = [PFUser query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
} else {
self.allUsers = objects;
[self.tableView reloadData];
}
}];
}
#pragma mark - Table view data source
- (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 [self.allUsers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
cell.textLabel.text = user.username;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end
Gabe Nadel
Treehouse Guest TeacherSo, the first thing I noticed was that this code belongs in the EditFriendsTableViewController.m file NOT the EditFriendsTableViewController.h file. Also, what errors or messages are you getting when the crash occurs?
glennseplowitz
13,859 PointsHi Gabe,
I made a mistake. The code is in the EditFriendsTableViewController.m file.
Glenn
Gabe Nadel
Treehouse Guest TeacherIf you place a breakpoint at this line:
PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
what is the value of self.allUsers when you stop the code there? Also, what is the value of indexPath?
glennseplowitz
13,859 PointsHi Gabe,
The value of self.allUsers is:
_allUsers __NSArrayM * @"4 objects" 0x00007f914ac89f90
[0] PFUser * 0x7f914ac5a220 0x00007f914ac5a220
[1] PFUser * 0x7f914ac63ea0 0x00007f914ac63ea0
[2] PFUser * 0x7f914ac6a0d0 0x00007f914ac6a0d0
[3] PFUser * 0x7f914ac0a090 0x00007f914ac0a090
The value of indexPath is:
indexPath NSIndexPath * 0xc000000000000016 0xc000000000000016
[0] unsigned long 0 0
[1] unsigned long 0 0
Thanks, Glenn
Gabe Nadel
Treehouse Guest TeacherIf you continue the program, what does the error say when it crashes?
Gabe Nadel
Treehouse Guest TeacherGabe Nadel
Treehouse Guest TeacherGlad I could be of "help" :)