iPhone Development: Force UITableView to show only complete cells

Tallymander uses UITableViewCells not only to display data but also to manipulate it. That means that partially-visible cells — that is, those that are cut off at the top or bottom of the view — aren’t terribly useful.

Better, I thought, would be to always ensure that when a partially-visible cell crops up, the UITableViewController will quietly nudge things to be completely visible.

Partially visible cells vs. Fully Visible Cells

In the first image, you can see the only part of the top and bottom cell. In the second image, the cells have been nudged so that everything visible is completely visible. This took a little noodling around with math but it wasn’t hard to do. Put this method into your UITableViewController subclass:

- (void)snapBottomCell
{
	NSInteger cellHeight = 62; //Cells for my view are 62px tall. Sub your own height here
 
	NSInteger offsetOverage = (NSInteger) self.tableView.contentOffset.y % cellHeight;
	//Use the tableview's contentOffset property and the cell height to determine how much is being cut off
 
	if (offsetOverage > 0)
	{
		//If the overage is more than 0, we should figure out what the new offset needs to be
 
		NSInteger newOffset;
 
		if (offsetOverage >= (cellHeight/2))
		{
			newOffset = self.tableView.contentOffset.y + (cellHeight - offsetOverage);
			//If the overage is greater than or equal to half the height of a cell, pull the cell up so it's fully visible
		}
 
		else {
			newOffset = self.tableView.contentOffset.y - offsetOverage;
			//Else, push the cell out of view
		}
 
		//With the new offset determined, animate the movement:
 
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:0.5];
		[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
		[self.tableView setContentOffset:CGPointMake(0, newOffset) animated:NO];
		[UIView commitAnimations];
 
	}
}

You’ll need to implement these two delegate methods as well:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
	[self snapBottomCell];
}
 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
	if (decelerate == NO)
	{
		[self snapBottomCell];
	}
}

And that’s it. If more than half of the bottom cell is visible, the cell gets nudged completely into view. If less than half is visible, it’s pushed out of view.

You could change snapBottomCell to accept cellHeight as an argument if you need to accommodate cells with variable heights. You might sort out a particular cell’s height like so:

	NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:CGPointMake(0, (self.tableView.frame.size.height - 1))];
	//Get the index path of the cell currently visible at the bottom edge of the tableview
 
	UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
 
	[self snapBottomCell:cell.frame.size.height];

There are cases where this isn’t useful: long lists whose primary function is selecting data for loading in another view, for example. Still, any time you’re using UITableViewCells to house controls or chunky bits of data, it might be good to ensure that only whole cells are displayed.


Tallymander 2.0 Post-Mortem

Tallymander 2.0 has been in the App Store for a few weeks. Here’s the story on my favorite product, so far.

Once upon a time…

Tallymander was born because once upon a time, I worked for the man and that meant wearing fancy pants and shirts that buttoned (the better to establish my image as a professional and advance my career). About once a month I rounded up my finery, counted it, and took it to the dry cleaners.

My mental math abilities could be bested by a fruit fly so I wondered if the App Store had anything to make the counting easier. They did, but it was either crap or too limited for my needs. The idea for Tallymander was born. I wanted to make something simple but useful.

I expected to make about $40 off of it, but I knew I wanted the challenge so I plowed ahead anyway. 1.0 shipped and people liked it. Really liked it! I got a handful of emails with kudos and feature requests. I wanted to get cracking on GlobeJot but decided I would spend a little time adding some customer requests to Tallymander first. A couple more weeks of development and Tallymander 1.1 was submitted. I forgot all about it.

Until one night, around midnight, when I got the “Ready for Sale” email that iPhone developers live for. Tallymander 1.1 was live.

And an App Store Staff Favorite. I peed myself a little. There followed a slew of copycat apps following this prominence. So it goes on the App Store.

The future

Tthanks to a handful of enthusiastic users and a little help from Apple, Tallymander managed to make me a tidy bit more money than the $40 I had expected. About $4,000 to date, in fact. Not bad for an app that started as a two week UX trial.

Continue Reading…


One of my proudest managed products: Turkey Tacos

I’ve had the product management bug since the early days of my childhood. While I have a stable of iPhone products that I spend the bulk of my time planning and developing, my need to make good stuff doesn’t end with software.

It extends entirely into the kitchen. I love cooking. It’s a creative act whose rewards are unrivaled by anything else. When you get it right, when the flavors and textures come together in a way that can satisfy and surprise, it feels incredible. Moreover, cooking is an important bit of empowerment. In today’s world of corporate food, unless you prepare it yourself, you’ll have no idea what’s truly happening on your plate. Cooking your own meals is the best way to understand your diet and cut out synthetic, unhealthy garbage. 90% of my meals come from my own kitchen prepared with ingredients that are as elemental as possible.

Cooking for me breaks down to about 25% experimentation and 75% refinement. That is, while I often try new things, I spend most of my time taking my established specialties and making them better. Of all of my kitchen products thus managed, I’m proudest of Turkey Tacos.

I love tacos: crunchy, savory and infinitely customizable. My favorite taco was always ground beef, but it had some drawbacks: greasy as hell yet the meat is paradoxically dry and crumbly. I don’t love ground turkey for many of the applications where it is recommended. Turkey burgers are odd, spongey, colorless things and turkey meatballs suffer from similar drawbacks.

Yet, for tacos, ground turkey is sublime. The meat breaks up into manageable, small chunks while remaining superbly moist and tender. The sponginess that is an indictment against turkey burgers is an asset for tacos, as the meat even after browning remains bursting with flavor.

The best part of turkey tacos: economy. They’re inexpensive to make and the prep time is less than 20 minutes.

Here’s my current, favorite formulation after over a dozen iterations. No sodium bomb flavor packet full of garbage, here. Just a tasty meal with ingredients you’ll look straight in the eye before cooking.

Turkey Tacos

You will need:

  • Half a pound of ground turkey
  • A can of simple, smooth tomato sauce (or, if you make yours from scratch, about a cup)
  • A 4oz can of Green Chile (diced green chile pepper is a delicious addition to any meal. You can usually find it among your other canned foods at the Supermarket or at Trader Joes. Sometimes it’s hiding among the ethnic foods. Use whatever temperature suits you. Of course, if you’re lucky enough to live in New Mexico, substitute canned for fresh)
  • A few spoonfuls of Frontera Chipotle salsa (can substitute with another splash of tomato sauce and some crushed red pepper, but seriously, find this salsa — it’s incredible)
  • Olive oil
  • Salt
  • Black pepper
  • Two cloves of garlic, minced or crushed
  • Blue corn taco shells (I’ve found that Whole Foods’ house brand is the best of these and costs the same as nasty garbage from Old El Paso)
  • Shredded cheese
  • Optional: Frontera Chipotle Garlic Taco Sauce. Absurdly good as a topping at the end

Preparation:

In a skillet or electric wok, heat two tablespoons of olive oil over medium heat, then add your garlic. Keep the garlic moving so it doesn’t burn. Once the garlic has gone from white to light brown, carefully add the turkey. Try to avoid pouring in any of the water or other fluid that your turkey may be sitting in — your olive oil will spatter otherwise. Break up the turkey into small chunks while you brown it, again keeping it moving to prevent burning. As the turkey browns, add a light sprinkle of salt and pepper, according to your preferences. Better to be conservative at this stage — you want just enough to lightly flavor the meat and you can always add more later before you serve.

Take moment to preheat your oven according to the directions on your taco shells.

Once the meat is evenly brown, with nothing pink left in your pan, add the green chiles. Since turkey is so much less fatty, you won’t need to drain the pan of grease as you would with ground beef at this stage. If anything, your pan may be getting a little dry and sticky, especially if it doesn’t have non-stick coating. Add a splash of olive oil if necessary to keep things lubricated. After about a minute, once the green chile is cooked through, stir in the tomato sauce.

After everything has been combined and the meat has a light, even coat of tomato sauce, turn off the heat and have a taste of your taco filling. If you’re satisfied with the spiciness and overall flavor, great, you’re all set. If you want to ratchet up the heat, though, add a few spoonfuls of the Chipotle Salsa, then taste again. Repeat until it’s just as you like it.

Let the filling rest and cool while you toast the taco shells according to the directions on their box. Usually about a minute at 400 degrees F. While the shells cook, transfer your taco filling to a serving bowl. Set the table with your bowl of turkey, the cheese, your taco sauce and the salsa. Bring the shells to the table, then let the table take turns building tacos. Two or more spoons in the turkey bowl are a good idea. Fill with turkey, top with sauce, salsa and cheese, to preferences. Makes about eight tacos.

A couple of notes: Like I said, I try to build with the most elemental, simple ingredients possible. At the same time, the Frontera Taco Sauce and Salsa are outstanding shortcuts. Short list of natural ingredients, made in small batches, no scary garbage and really, really tasty. Besides all that, Rick Bayless is the man. Why blue corn? It’s a better shell. Crispy but firm. Your tacos won’t fall apart mid-way through eating.

From an earlier iteration, before discovering the perfection of blue corn shells.

Leftovers from an earlier iteration, before discovering the perfection of blue corn shells. Look at that gorgeous filling!

Another earlier iteration. I was using some mild salsa and tobasco to get toward the heat I wanted. The Frontera Chipotle Salsa produces much better results.

Another earlier iteration. I was using some mild salsa and tobasco to get toward the heat I wanted. The Frontera Chipotle Salsa produces much better results.

It took a lot... testing to ensure I had the right Frontera salsa for the job. My favorite remains Chipotle but the other flavors are also delicious and great for chips.

It took a lot of... testing to ensure I had the right Frontera salsa for the job. My favorite remains Chipotle but the other flavors are also delicious and great for chips.


Little Things: Don’t Ignore ‘Em

I saw this Bing ad on Facebook:

Bing Ad

See the little movement lines, there on the left? They suggest the weird little dollar coin is moving from left to right. In western cultures (to whom the ad was targeted) left to right progression is associated with forward motion, while right to left progression signals backward motion. This something you’ll see in movies and comic strips if you’re looking for it. Here’s an example we all know and love:

back-to-the-future

The stylized arrow beside the word “Back” is pointing, appropriately, back, via a right-to-left perspective, while all of the letters in that word are also skewed right-to-left. The word “future,” conversely, is skewed left-to-right. It’s an instantly recognizable logo that succeeds by embodying its idea without whacking you over the head with it.

So look again:

Bing Ad

Bing is talking about getting cash back, but illustrating their point by showing cash flowing away. This isn’t the economy to be talking about cash flowing away. I’m not sure that the dissonance this creates registers for most people but when it’s already unlikely that people will engage with your ad unit, the last thing you do is add subconscious resistance.

Yeah, it’s tiny, but the tiny things pile up into the enormous sand dunes that dog every last Microsoft endeavor with needless, unnecessary friction born of poor taste and obliviousness.

For more on this, enjoy a deconstruction of the hideous Bing logo.


SwedeShop

I remember the first time I went to IKEA.

It blew my brain open. It’s the coolest retail experience in the history of the world.

There’s only one problem: you gotta keep track of a lot of data if you want to get out of there with everything you wanted to take home.

Enter SwedeShop, my unofficial IKEA shopping list app. Find out more at the main site:

http://www.danilocampos.com/apps/swedeshop/


Next

Prev