I have this code that where I would normally use one line:
if (tableView == self.searchDisplayController.searchResultsTableView)
{
NSLog(@"Configuring cell to show search results");
shoppingList = [self.searchResults objectAtIndex:indexPath.row];
cell.textLabel.text = shopList.name;
cell.textLabel.text = shopList.type;
cell.textLabel.text = shopList.price;
cell.textLabel.text = shopList.occasion;
}
The reason I have this is that I am implementing a scope under my search bar.
Now the scope works, when I type in a name I would expect to see the name when I select the first scope which is the name of the product.
What is happening however is that it shows what is under occasion, since it is the last one in the list (I pressume). So when I type in the name of a product it comes up with the matching occasion instead of the name of the product.
How do I set it up that it shows what I select in the scope?
I have implemented the following method, to make the scope work correctly, just the labels are not coming up right, which is affected in the tableView section code above.
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
Any help is great:-)
Thanks.
The
=operator is theassignmentoperator. That means that whatever is on the left side of the=operator is going to become whatever is on the right side after that line of code is executed.For example:
int i = 5;i = 4;
i = 3;
i = 8;
After all four of those lines are executed,
iis equal to8. It doesn’t matter that it was another value previously–the=operator obliterates whatever was in the variable before and places the new value into it.So, regardless of what you want your code to do, what you are doing is obliterating the value of
cell.textlabel.textevery time you use the=operator.shopList.name,shopList.type, andshopList.pricedon’t exist anymore after you setcell.textlabel.texttoshopList.occasion, for the same reasoni = 8in my above example. This is a fundamental and hugely important programming concept.Do you understand what’s wrong, now? If you want to save all four items–price, name, type, and occasion–you need four separate variables to do so.
As an aside, I’m fairly certain you aren’t using the word
scopeproperly (unless I’m entirely misunderstanding the purpose of your program). From Wikipedia: