Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Create two UITableViewCell classes. One for your usual view, one that has a FinanceTextField. Load them both in from xibs. In your cellForIndexPath, determine which cell you want to use, and load (and reuse) the appropriate type. Even though only one cell uses the different cell, it will all work. In fact, you can have all different types of cells in the same table, all determinant on the row, such as the first row with regular label text, the second with a textfield, the third with a button, etc.</p> <p>There's a sample project you can look to do this. The "Recipes" sample on the apple's developer website. Here's a part of the code you might be interested in :</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = nil; // For the Ingredients section, if necessary create a new cell and configure it with an additional label for the amount. Give the cell a different identifier from that used for cells in other sections so that it can be dequeued separately. if (indexPath.section == INGREDIENTS_SECTION) { NSUInteger ingredientCount = [recipe.ingredients count]; NSInteger row = indexPath.row; if (indexPath.row &lt; ingredientCount) { // If the row is an ingredient, configure the cell to show the ingredient name and amount. static NSString *IngredientsCellIdentifier = @"IngredientsCell"; cell = [tableView dequeueReusableCellWithIdentifier:IngredientsCellIdentifier]; if (cell == nil) { // Create a cell to display an ingredient. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IngredientsCellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; } Ingredient *ingredient = [ingredients objectAtIndex:row]; cell.textLabel.text = ingredient.name; cell.detailTextLabel.text = ingredient.amount; } else { // If the row is not an ingredient the it's supposed to add an ingredient static NSString *AddIngredientCellIdentifier = @"AddIngredientCell"; cell = [tableView dequeueReusableCellWithIdentifier:AddIngredientCellIdentifier]; if (cell == nil) { // Create a cell to display "Add Ingredient". cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AddIngredientCellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } cell.textLabel.text = @"Add Ingredient"; } </code></pre> <p>This is just a part of the project that shows how to create different identifiers. From here you can get it all by yourself...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload