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 trialRashii Henry
16,433 PointsSearch Bar with Segmented Control for tableView?
Would anyone happen to know how i can use the UISearchBar that comes with the scopeBar (in interface Builder) to dynamically switch between 3 different prototype cells within one tableView.
I have a TableViewController with its own subclass. I've added the searchBar with the scope bar to the project.
The Goal: Im using the search bar to search through the friends, but i want the information to change when i select a certain index of the segmented control/scope bar.
What i have now: within the cellForRowAtIndexPath method I'm using a switch case to transition between the selected states of the scope bar.
switch (self.mySearchBar.selectedScopeButtonIndex)
{
case 0:
self.cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
return self.cell;
break;
case 1:
self.cell2 = [tableView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
return self.cell2;
break;
}
seems simple. However, i cant figure out a way to return a different prototype Cell depending on the selected index. I've declared the cells in the header (to make them accessible globally) but the return function will not allow me to return a specific prototype cell based on the selected index of the scope bar.