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 trial
Eric Ellenbrook
9,006 PointsRibbit Crashing on Adding Check Marks When Table View is Loaded
Alright, everything has been working great up until now. The problem is that when I click the edit friends button, the app crashes with no information. It sends me to a breakpoint at this line of code:
if ([self isFriend:user]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
I've spent the last 30 minutes trouble shooting and I did the video two times so I feel like everything is correct (I'm sure it is not, however).
I've put an NSLog in the prepareForSegue method and it logs the array just fine so the information is there. I feel like something is wrong with that method though. Also the segue identifier is correct. I have checked it at least 5 times.
I will note that up until now the app has been working perfectly. I'll add the code that I added for this exercise.
FriendsViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface FriendsViewController : UITableViewController
@property(strong, nonatomic) PFRelation *friendsRelation;
@property(strong, nonatomic) NSArray *friends;
@end
FriendsViewController.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"showEditFriends"]) {
EditFriendsViewController *viewController = (EditFriendsViewController *)segue.destinationViewController;
viewController.friends = [NSMutableArray arrayWithArray:self.friends];
}
}
EditFriendsViewController.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface EditFriendsViewController : UITableViewController
@property(strong, nonatomic) NSArray *allUsers;
@property(strong,nonatomic) PFUser *currentUser;
@property(strong,nonatomic) NSMutableArray *friends;
-(BOOL)isFriend:(PFUser *)user;
@end
EditFriendsViewController.m
- (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;
if ([self isFriend:user]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
and helper method
#pragma mark - Helper Methods
- (BOOL) isFriend:(PFUser *)user {
for (PFUser *friend in self.friends) {
if ([friend.objectId isEqualToString:user.objectId]) {
return YES;
}
}
return NO;
}
If there as anything else that you need to see I'll be monitoring this thread. I appreciate any help that anybody can give me! I'm so lost. Thanks!
Edit: Formatting
3 Answers
Eric Ellenbrook
9,006 PointsI have fixed it. The breakpoint was stuck from the first time that I had the issue so it was "crashing" (stopping) every single time I ran the app. Once I deleted all breakpoints it ran perfectly. Simple but fixed. Thanks for the help everybody, I do appreciate it greatly.
James Andrews
7,245 PointsDid you make sure the UiTableViewCell has a identifier of "Cell" in the storyboard?
Eric Ellenbrook
9,006 PointsYes, for both Friends and Edit Friends view controllers
Eric Ellenbrook
9,006 PointsI did find one error in FriendsViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.friends.count;
}
should have been
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.friends count];
}
Unfortunately this still doesn't work. :( Any help anybody?I went through the last three videos three more times and everything is fine.