two custom cells in a UITableView - ios

I am trying to use two custom cells inside a UITableView. The problem I am running into is that my return is not being called in the right place. I am not sure what I need to implement the return to stop the control from reaching the end of a non-void function.
Here is the code inside my cellforrowatindex.
static NSString *kCellID = #"MessageCell";
static NSString *UCellID = #"UnreadCell";
if (status == 0)
{
//static NSString *kCellID = #"MessageCell";
MessageListCell *cell = (MessageListCell *) [tableView dequeueReusableCellWithIdentifier:kCellID];
if (priority == 0)
{
cell. imageviewImportance.image = nil;
}
if (priority == 1)
{
cell.imageviewImportance.image = [UIImage imageNamed:#"single exclamation.png"];
}
if (priority == 2)
{
cell.imageviewImportance.image = [UIImage imageNamed:#"double exclamation mark.png"];
}
if (priority == 3)
{
cell.imageviewImportance.image = [UIImage imageNamed:#"triple exclamation kmar.png"];
}
//if (status == 0)
//{
cell.backgroundColor = [UIColor clearColor];
cell.labelFrom.text = [NSString stringWithFormat:#"From: %#",m.From];
cell.labelFrom.font = [UIFont boldSystemFontOfSize:17];
cell.labelSubject.text = subject;
cell.labelSubject.font = [UIFont boldSystemFontOfSize:17];
cell.labelTime.text = time;
cell.labelTo.text = [NSString stringWithFormat:#"To: %#",m.To];
cell.labelTo.font = [UIFont boldSystemFontOfSize:17];
return cell;
}
else if (status != 0)
{
//static NSString *UCellID = #"UnreadCell";
MessageListCell *cell = (MessageListCell *)[tableView dequeueReusableCellWithIdentifier:UCellID];
cell.backgroundColor = [UIColor clearColor];
cell.unreadLabelFrom.text = [NSString stringWithFormat:#"From: %#",m.From];
cell.unreadLabelSubject.text = subject;
cell.unreadLabelTo.text = [NSString stringWithFormat:#"To:%#",m.To];
cell.unreadLabelTime.text = time;
return cell;
}
//NSLog(#"description = %#",[cell description]);
//return cell;
}

Simply change the else if to else, then the compiler will stop complaining.
The way you have it now is telling the compiler to check 2 condition, what if none of them are met? what is going to be returned?
You will need a else block but since your else if is redundant so else is what you need.
if (status == 0)
{
static NSString *kCellID = #"MessageCell";
MessageListCell *cell = (MessageListCell *) [tableView dequeueReusableCellWithIdentifier:kCellID];
NSString *imageName;
switch (priority) {
case 0:
imageName = nil;
break;
case 1:
imageName = #"single exclamation.png";
break;
case 2:
imageName = #"double exclamation mark.png";
break;
case 3:
imageName = #"triple exclamation kmar.png";
break;
default:
break;
}
cell.imageviewImportance.image = [UIImage imageNamed:imageName];
cell.backgroundColor = [UIColor clearColor];
cell.labelFrom.text = [NSString stringWithFormat:#"From: %#",m.From];
cell.labelFrom.font = [UIFont boldSystemFontOfSize:17];
cell.labelSubject.text = subject;
cell.labelSubject.font = [UIFont boldSystemFontOfSize:17];
cell.labelTime.text = time;
cell.labelTo.text = [NSString stringWithFormat:#"To: %#",m.To];
cell.labelTo.font = [UIFont boldSystemFontOfSize:17];
return cell;
}
else
{
static NSString *UCellID = #"UnreadCell";
MessageListCell *cell = (MessageListCell *)[tableView dequeueReusableCellWithIdentifier:UCellID];
cell.backgroundColor = [UIColor clearColor];
cell.unreadLabelFrom.text = [NSString stringWithFormat:#"From: %#",m.From];
cell.unreadLabelSubject.text = subject;
cell.unreadLabelTo.text = [NSString stringWithFormat:#"To:%#",m.To];
cell.unreadLabelTime.text = time;
return cell;
}

Related

After setting selectedBackgroundView of UITableViewCell when the cell is selected, background color of other components get changed

Due to some permission issue, in my tableView some cell can be selected by user and some cell can't be selected by that user. What I did in my cellForRowAtIndexPath is:
-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
int row = (int)[indexPath row];
static NSString *simpleTableIdentifier = #"EditProjectTableCell";
Project* project = (Project*)[self.projectList objectAtIndex:row];
EditProjectTableCell *cell = (EditProjectTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleTableIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.serial.layer.cornerRadius = 5;
cell.accessoryView = [[ UIImageView alloc ] initWithImage:[UIImage imageNamed:#"accessory_right.png"]];
cell.cellView.backgroundColor = [UIColor blackColor];
cell.backgroundColor = [UIColor blackColor];
}
if ([project.role isEqualToString:#"1"] || [project.role isEqualToString:#"2"]) {
UIView *customView = [[UIView alloc] initWithFrame:cell.frame];
customView.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = customView;
}
else cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(cell.imageFetchOperation != nil) [cell.imageFetchOperation cancel];
cell.imageFetchOperation = [[CellBlockOperation alloc] initWithIndexPath:indexPath
andPkId:project.pkId
andFetchImage:YES
andFetchReportCounter:NO
andFetchIssueCounter:NO
andFetchDrawingCounter:NO
andDelegate:self];
if(cell.counterFetchOperation != nil) [cell.counterFetchOperation cancel];
cell.counterFetchOperation = [[CellBlockOperation alloc] initWithIndexPath:indexPath
andPkId:project.pkId
andFetchImage:NO
andFetchReportCounter:YES
andFetchIssueCounter:NO
andFetchDrawingCounter:NO
andDelegate:self];
cell.projectName.text = project.name;
cell.projectNumber.text = project.number;
cell.owner.text = [NSString stringWithFormat:#"%# %#",project.ownerName,project.ownerLastName];
NSString* temp_date = [Utils stringFromDateForGUI:project.creationDate];
cell.date.text = temp_date;
[cell.syncStatusView setImage:[Utils getImageForSyncStatus:project.isDirty.intValue]];
NSNumber *ret = [self.reportCountList objectForKey:project.pkId];
if(ret == nil) {
cell.serial.text = #"";
[cell.counterFetchOperation setPkId:project.pkId];
[self.tableCellUpdateQueue addOperation:cell.counterFetchOperation];
} else {
cell.serial.text = [NSString stringWithFormat:#"%d",[ret intValue]];
}
id img = [self getSmallImage:project.pkId andIndexPath:indexPath andCell:cell];
if(img == nil || img == (id)[NSNull null]) {
img = [UIImage imageNamed:#"gray-img.jpg"];
cell.iconImageView.image = [UIImage imageNamed:#"project-icon.png"];
cell.iconImageView.hidden = NO;
} else {
cell.iconImageView.hidden = YES;
}
cell.imageView.image = (UIImage*)img;
if ([project.role isEqualToString:#"2"] || [project.role isEqualToString:#"1"])
cell.selectImageView.hidden = NO;
else
cell.selectImageView.hidden = YES;
return cell;
}
Selection part is working just fine. But if a cell is selected then the background color of a UILabel gets changed to clear color. See the below images for clear idea.
Before selection:
After Selection :

Issue Displaying Multiple Beacons in TableView

I am trying to display multiple beacons in a tableView. The minor values, name, and images for each beacon are stored in core data. While the name and image of the beacon are appearing in the tableView cell correctly, the proximity always changing to the closest beacon.
I really appreciate the help!
DisplayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CellID"];
Tag *tag = [self.tags objectAtIndex:indexPath.row];
cell.textLabel.text = #"";
NSData *data = tag.image;
UIImage *image = [UIImage imageWithData:data];
cell.imageView.image = image; //BEACONS
if (self.tags.count > 0)
{
self.arrow.hidden = true;
self.addLabel.hidden = true;
CLBeacon *beacon = [self.beacons objectAtIndex:indexPath.row];
NSString *proximityLabel = #"";
switch (beacon.proximity)
{
case CLProximityFar:
proximityLabel = [NSString stringWithFormat:#"Your %# is Far", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(255/255.0) green:(107/255.0) blue:(105/255.0) alpha:1];
break;
case CLProximityNear:
proximityLabel = [NSString stringWithFormat:#"Your %# is Near", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(96/255.0) green:(102/255.0) blue:(232/255.0) alpha:1];
break;
case CLProximityImmediate:
proximityLabel = [NSString stringWithFormat:#"Your %# is Close", tag.name];
cell.backgroundColor = [UIColor colorWithRed:(118/255.0) green:(225/255.0) blue:(167/255.0) alpha:1];
break;
case CLProximityUnknown:
proximityLabel = #"Fetching Location";
cell.backgroundColor = [UIColor whiteColor];
break;
}
cell.nameLabel.text = tag.name;
NSString *detailLabel = [NSString stringWithFormat:#"%#, Dist: %0.001f", proximityLabel, beacon.accuracy];
cell.proxLabel.text = detailLabel;
self.tableView.hidden = false;
self.mapView.hidden = false;
}
return cell;
}

Comparison between variables & change label colour

I've a TableView which is containing two variable on each row and it is refreshing every 2 seconds via getting data from the server. I want to change the labels colour every update if it is higher or lower in red or green. So please how can I do that? While I know how to change the label colour but don't know how to make the compression between each 2 seconds.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"comCell";
comTableViewCell *cell = (comTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
NSArray *parts = [[NSBundle mainBundle] loadNibNamed:#"comTableViewCell" owner:nil options:nil];
cell = [parts objectAtIndex:0];
}
id rowObject = [data1 objectAtIndex:indexPath.row];
[cell.lblType setText:[rowObject objectForKey:#"strSymbol"]];
[cell.lblOffer setText:[rowObject objectForKey:#"strOffer"]];
[cell.lblBid setText:[rowObject objectForKey:#"strBid"]];
cell.lblType.font = [UIFont fontWithName:#"Helvetica" size:12.0f];
cell.lblOffer.font = [UIFont fontWithName:#"Helvetica" size:12.0f];
cell.lblBid.font = [UIFont fontWithName:#"Helvetica" size:12.0f];
cell.lblType.textColor = [UIColor blackColor];
cell.lblOffer.textColor = [UIColor whiteColor];
cell.lblBid.textColor = [UIColor whiteColor];
return cell;
}
Data result:
{
strBid = "1.29158";
strOffer = "1.29258";
strSymbol = "USD/EUR";
},
{
strBid = "98.964";
strOffer = "99.004";
strSymbol = "AUD/JPY";
},
{
strBid = "11.2472";
strOffer = "11.2972";
strSymbol = "USD/ZAR";
}
Update:
data2 = data1;
id rowObject2 = [data2 objectAtIndex:indexPath.row];
NSString *new_offer = [rowObject2 objectForKey:#"strOffer"];
if (data2 != nil) {
id old_rowObject = [data2 objectAtIndex:indexPath.row];
NSString *old_offer = [old_rowObject objectForKey:#"strOffer"];
if ([new_offer doubleValue] > [old_offer doubleValue]) {
cell.lblOffer.textColor = [UIColor greenColor];
cell.lblBid.textColor = [UIColor greenColor];
}
else if ([new_offer doubleValue] == [old_offer doubleValue]) {
cell.lblOffer.textColor = [UIColor blackColor];
cell.lblBid.textColor = [UIColor blackColor];
}
else {
cell.lblOffer.textColor = [UIColor redColor];
cell.lblBid.textColor = [UIColor redColor];
}
} else {
// first time getting data.
}
return cell;
}
Update:
move this line data2 = data1; to the place you start parse the json. before the code you use to parse.
Old Post:
- (void)parserDidStartDocument:(NSXMLParser *)parser {
old_data = data1; <<-- saves data here!
data1 = [[…. alloc] init];
}
id rowObject = [data1 objectAtIndex:indexPath.row];
NSString *new_offer = [rowObject objectForKey:#"strOffer"];
if (old_data != nil) {
id old_rowObject = [old_data objectAtIndex:indexPath.row];
NSString *old_offer = [old_rowObject objectForKey:#"strOffer"];
if ([new_offer doubleValue] > [old_offer doubleValue]) {
// set colour here.
} else {
// and here.
}
} else {
// first time getting data.
}

UiSegementedController's segment automatically select in UITableViewCell when scroll the uitableview

I have added UISegmentedController to TableViewCell in CellForRowAtIndexPath.
Following is the code.
[cell.segStatus addTarget:self action:#selector(selectedSegmentControl:) forControlEvents: UIControlEventValueChanged];
[cell.segStatus setSegmentedControlStyle:UISegmentedControlStyleBar];
cell.segStatus.tag = indexPath.row;
I use UITableViewCell class for customized class.
I select segment and when I scroll the tableview some other cell's segmented controller also automatically select.
Why is it? how can I sort out this ?
Full CellForRowAtIndexPath Method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#try {
static NSString *defTableIdentifier = #"DefectRegisterCell";
DefectRegisterCell *cell = (DefectRegisterCell *)[self.tblDefectList dequeueReusableCellWithIdentifier:defTableIdentifier];
_defectEntry = [defectObjList objectAtIndex:indexPath.row];
cell.lblDefectNo.text = [NSString stringWithFormat:#"%#", _defectEntry.defectNo];
if ([_defectEntry.defect isEqual:#"None"] || [_defectEntry.defect isEqual:#""] ) {
cell.lblDefect.text = [NSString stringWithFormat:#"%# - %# - Passed", _defectEntry.item,_defectEntry.subItem];
}
else{
cell.lblDefect.text = [NSString stringWithFormat:#"%# - %# - %#", _defectEntry.item,_defectEntry.subItem,_defectEntry.defect];
}
cell.lblLocation.text = #"Location:";
cell.lblLocationValue.text = [NSString stringWithFormat:#"%# > %# > %# > %# (%# - %#)",_defectEntry.building, _defectEntry.area, _defectEntry.location, _defectEntry.room,_defectEntry.orient, _defectEntry.position];
cell.lblAssignedTo.text = #"Assigned to:";
cell.lblAssignedToValue.text = _defectEntry.responsibleComp;
cell.lblDue.text = #"Due:";
cell.lblDueValue.text = _defectEntry.dueDate;
cell.lblCapturedBy.text = #"Recorded by:";
cell.lblCapturedByValue.text = [NSString stringWithFormat:#"%# (%#)",_defectEntry.inspectedId,_defectEntry.inspectedCompId];
cell.lblDate.text = #"On:";
cell.lblDateValue.text = _defectEntry.createdDate;
NSString *attached = #"0" ;
NSString *fixClaimed = #"0";
NSString *completed = #"0";
if ([_defectEntry.attached length] > 0) {
attached = #"1";
}
if ([_defectEntry.fixClaimed isEqualToString:#"Y"]) {
fixClaimed = #"1";
}
if ([_common checkDateValidation:_defectEntry.completed]) {
completed = #"1";
}
[cell.segStatus addTarget:self action:#selector(selectedSegmentControl:) forControlEvents: UIControlEventValueChanged];
[cell.segStatus setSegmentedControlStyle:UISegmentedControlStyleBar];
cell.segStatus.tag = indexPath.row;
if ([attached isEqualToString:#"1"]) {
cell.imgAttachment.image = [UIImage imageNamed:#"diAttachments.png"];
}
if ([fixClaimed isEqualToString:#"1"]) {
cell.imgDefect.image = [UIImage imageNamed:#"diWarning.png"];
cell.segStatus.hidden = NO;
} else if ([completed isEqualToString:#"1"]) {
cell.imgDefect.image = [UIImage imageNamed:#"diRight.png"];
if ([_defectEntry.passed isEqualToString:#"Yes"]) {
cell.segStatus.hidden = YES;
}
else{
cell.segStatus.hidden = NO;
}
} else {
cell.imgDefect.image = [UIImage imageNamed:#"diWrong.png"];
cell.segStatus.hidden = NO;
}
UIView *backgroundView = [[UIView alloc] init];
if (indexPath.row % 2) {
backgroundView.backgroundColor = [UIColor whiteColor];
} else {
backgroundView.backgroundColor = [UIColor colorWithRed:242/255.0f green:242/255.0f blue:242/255.0f alpha:1.0f];
}
cell.backgroundView = backgroundView;
//change the selected cell color
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = gaSelectedColor;
cell.selectedBackgroundView = selectedBackgroundView;
return cell;
}
#catch(NSException *excp)
{
NSLog(#"%#",excp);
}
}

UITableView loading wrong prototype cell from storyboard

I am having a really weird error that I cannot figure out, I really need some help right now. Basically, the tableView has three UITableViewCell subclasses that have their own prototype cell, and appear in their own section. But the prototype that is in the third section is also appearing in the second section. The weird part is that after putting some NSLogs into my code, the cell that is showing up in the second section section (which should be in the third section) is the correct subclass of UITableViewCell, but the content from the other prototype is showing up. I have no idea why this is happening. I have check to make sure the prototypes are of the right subclass, and the identifiers are all correct, and they are. Has anyone encountered this problem before? Sorry in advance for how long my cellForRowAtIndexPath: method is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WaveDetailCell *waveDetails;
ActionsCell *actions;
CommentCell *comments;
id cellToReturn;
if (self.hasAgrees || self.hasComments)
{
switch (indexPath.section)
{
case 0:
{
waveDetails = [tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:#selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = #{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageview
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(2.0f, 2.0f)];
cellToReturn = waveDetails;
}
break;
case 1:
{
if (self.hasAgrees)
{
//create agrees cell
}
else
{
actions = [tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
}
case 2:
{
if (self.hasAgrees)
{
//if there are agrees, and no comments, then the last section should be the actions cell
actions = [tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
else
{
//there are comments, and no agrees
comments = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath];
CommentObject *comment = [self.currentWaveObject.commentsArray objectAtIndex:indexPath.row];
comments.userNameLabel.text = comment.commenterID;
comments.commentLabel.text = comment.commentText;
comments.timeStampLabel.text = comment.timeStamp;
[self setCornerRadiusForImageView:comments.userImageView withRadius:CGSizeMake(3.0f, 3.0f)];
cellToReturn = comments;
}
}
default:
break;
}
}
else if (self.hasComments && self.hasAgrees)
{
switch (indexPath.section)
{
case 0:
{
waveDetails = (WaveDetailCell *)[tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:#selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = #{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageview
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(0.5f, 0.5f)];
cellToReturn = waveDetails;
}
break;
case 1:
{
//create agrees cell
}
break;
case 2:
{
actions = (ActionsCell *)[tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
break;
case 3:
{
comments = (CommentCell *)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath];
CommentObject *comment = [self.currentWaveObject.commentsArray objectAtIndex:indexPath.row];
comments.userNameLabel.text = comment.commenterID;
comments.commentLabel.text = comment.commentText;
comments.timeStampLabel.text = comment.timeStamp;
[self setCornerRadiusForImageView:comments.userImageView withRadius:CGSizeMake(2.0f, 2.0f)];
cellToReturn = comments;
}
break;
default:
break;
}
}
else
{
if (indexPath.row == 0)
{
waveDetails = (WaveDetailCell *)[tableView dequeueReusableCellWithIdentifier:WaveDetailCellIdentifier forIndexPath:indexPath];
if ([waveDetails.waveLabel respondsToSelector:#selector(setAttributedText:)])
{
NSString *name = self.currentWaveObject.wavedToUserID;
NSString *fullWaveString = [name stringByAppendingString:self.currentWaveObject.waveString];
NSRange range = [fullWaveString rangeOfString:self.currentWaveObject.wavedToUserID];
UIFont *font = [UIFont fontWithName:HelveticaMedium size:16.0f];
NSDictionary *attrs = #{NSFontAttributeName: font};
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:fullWaveString];
[attributedString addAttributes:attrs range:range];
[waveDetails.waveLabel setAttributedText:attributedString];
}
waveDetails.wavedByNameLabel.text = self.currentWaveObject.wavedByUserID;
waveDetails.timestampLabel.text = self.currentWaveObject.creationDate;
//round the corners of the imageviews
[self setCornerRadiusForImageView:waveDetails.profilePicImageView withRadius:CGSizeMake(4.0f, 4.0f)];
[self setCornerRadiusForImageView:waveDetails.waverProfileImageView withRadius:CGSizeMake(0.5f, 0.5f)];
cellToReturn = waveDetails;
}
else
{
actions = (ActionsCell *)[tableView dequeueReusableCellWithIdentifier:ActionsCellIdentifier forIndexPath:indexPath];
cellToReturn = actions;
}
}
return cellToReturn;
}
Wait, I figured it out. This is embarrassing, but I forgot a break in one of the cases in the switch statement!

Resources