best approach for tableview with rows expand and collapse option - ios

I have view which contains tableview and searchbar. When i begin searching it should search the tableview. Below is the sample data of tableview in attached image:
STUDENT 1, STUDENT 2 are different sections in the table
Suppose i search for "S" then result should be as shown below where matched rows should be visible and unmatched rows - should be hidden and a button "Show Remaining" should be visible. When i click on "Show Remaining" button it should show remaining rows of the same section :
how do i achieve this and if possible please provide the example for above scenario.

I had created the code for your requirement please find the below url for download the code and review it.
Link : https://www.dropbox.com/s/22ijwgxybn98wyj/ExpandCollapse.zip?dl=0
Environment : Xcode 8 and Objective-C
Highlight of the code which I had done it.
I had created NSObject of student based on your structure, create two(StudentListCell and ShowMoreCell) UITableViewCell for display the record of student and "Show Remaining button" record.
Also I have taken two(arrStudentInfo, arrSearchInfo) NSMutablebleArray for keeping the search records and original records.
After that I initilize the NSObject of student in ViewController.m. Please find the below code.
- (void)setupData {
self.arrStudentInfo = [[NSMutableArray alloc] init];
self.arrSearchInfo = [[NSMutableArray alloc] init];
StudentInfo *student_1 = [[StudentInfo alloc] init];
student_1.name = #"Sia S";
student_1.style = #"S";
student_1.trend = #"S";
student_1.age = #"60";
student_1.locale = #"Node";
student_1.street = #"BR";
student_1.city = #"JP";
student_1.country = #"US";
student_1.isOpen = YES;
student_1.isShowMore = NO;
[self.arrStudentInfo addObject:student_1];
StudentInfo *student_2 = [[StudentInfo alloc] init];
student_2.name = #"Nitin";
student_2.style = #"N";
student_2.trend = #"N";
student_2.age = #"40";
student_2.locale = #"Node";
student_2.street = #"BR";
student_2.city = #"SP";
student_2.country = #"US";
student_2.isOpen = YES;
student_2.isShowMore = NO;
[self.arrStudentInfo addObject:student_2];
}
I had created the method which return the currently active which means search record or original record of array.
- (NSMutableArray *)getCurrentArray {
if(self.isSearch)
return self.arrSearchInfo;
else
return self.arrStudentInfo;
}
Load the data based on scenario,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
StudentInfo *studentInfo = [self getCurrentArray][indexPath.section];
if(indexPath.row == SHOW_MORE_INDEX && studentInfo.isShowMore == NO) {
static NSString *strCellIdentifier = #"ShowMoreCell";
ShowMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIdentifier];
cell.btnShowMore.tag = indexPath.section;
[cell.btnShowMore addTarget:self action:#selector(clickONShowMore:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
else {
static NSString *strCellIdentifier = #"StudentListCell";
StudentListCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIdentifier];
[cell setupCell:studentInfo indexPath:indexPath];
return cell;
}
}
For searching the student name,
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
self.isSearch = YES;
NSPredicate *predicateStudent = [NSPredicate predicateWithFormat:[NSString stringWithFormat:#"self.name CONTAINS[cd] '%#'",searchBar.text]];
NSArray *arrGetSearch = [self.arrStudentInfo filteredArrayUsingPredicate:predicateStudent];
if(self.arrSearchInfo.count)
[self.arrSearchInfo removeAllObjects];
[self.arrSearchInfo addObjectsFromArray:arrGetSearch];
[self.tblView reloadData];
}
And again load the original record if user click on "X" button on UISearchbar.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if([searchText isEqualToString:#""] || searchText==nil) {
[searchBar resignFirstResponder];
self.isSearch = NO;
[self.tblView reloadData];
}
}
Hope this will work for you.

There are many examples available for expand and collapse table.
You can refer below example
http://www.appcoda.com/expandable-table-view/
By setting up dynamically in plist file. you can maintain expandable and collapsable tableview.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let currentCellDescriptor = getCellDescriptorForIndexPath(indexPath)
let cell = tableView.dequeueReusableCellWithIdentifier(currentCellDescriptor["cellIdentifier"] as! String, forIndexPath: indexPath) as! CustomCell
if currentCellDescriptor["cellIdentifier"] as! String == "idCellNormal" {
if let primaryTitle = currentCellDescriptor["primaryTitle"] {
cell.textLabel?.text = primaryTitle as? String
}
if let secondaryTitle = currentCellDescriptor["secondaryTitle"] {
cell.detailTextLabel?.text = secondaryTitle as? String
}
}
else if currentCellDescriptor["cellIdentifier"] as! String == "idCellTextfield" {
cell.textField.placeholder = currentCellDescriptor["primaryTitle"] as? String
}
else if currentCellDescriptor["cellIdentifier"] as! String == "idCellSwitch" {
cell.lblSwitchLabel.text = currentCellDescriptor["primaryTitle"] as? String
let value = currentCellDescriptor["value"] as? String
cell.swMaritalStatus.on = (value == "true") ? true : false
}
else if currentCellDescriptor["cellIdentifier"] as! String == "idCellValuePicker" {
cell.textLabel?.text = currentCellDescriptor["primaryTitle"] as? String
}
else if currentCellDescriptor["cellIdentifier"] as! String == "idCellSlider" {
let value = currentCellDescriptor["value"] as! String
cell.slExperienceLevel.value = (value as NSString).floatValue
}
return cell
}

I can't think of any general "best approach" for collapsing/expanding behaviour in UITableView. I suspect that is the reason why there's no provided by Apple. Instead, they gave us enough instruments to implement it the way we wish.
In your particular case I have next vision.
I don't know, and don't need to know, how exactly do you work with model side of your task and the following code serves only this answer's purpose, which is - to provide you with collapsing behaviour you seek.
I would suggest to implement your desired behaviour in such a manner. In ViewController, in which you control both search bar and table view add fields
#property NSArray* filteredStudents;
#property NSMutableIndexSet* expandedStudents;
Those properties would be nil (or empty instances) while no search is taking place. Once search starts (first symbols entered or "Search" button tapped - whatever you like most) - instantiate them.
filteredStudents - array that holds reference to those students, that satisfy your search criteria. It is updated every time search executed. Each time you update it - do [tableView reloadData].
expandedStudents - index set that tells you in which sections have user pressed "Show all". Don't forget - it holds only section numbers. So, when filteredStudents array changes, you have to update it manually. For example, when you entered "S" - you have two students shown. You press Show All on the second student. expandStudents now has number 1 in it. Than you enter "Se", and only second student remains. You have to, in that case, replace 1 in expandedStudents with 0, 'cause second student's section becomes first.
Another property
#property BOOL searchMode;
This property should be YES whenever filtered results display takes place. NO - otherwise.
Next, modify UITableViewDataSource and Delegate methods like this
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
if(searchMode) {
return self.filteredStudents.count;
}
else {
//Your current behaviour here
}
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(searchMode) {
if([self.expandedStudents containsIndex:section]) { // Button "Show all" was already tapped for this student
return /* Number of all fields you need to show for student. Just like you do now. It is for expanded section */
}
else {
return /* Number of fields that satisfy search criteria for student self.filteredStudents[section] */
}
}
else {
//Your current behaviour here
}
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(searchMode) {
if(![self.expandedStudents containsIndex:section] && /* indexPath corresponds to place, where "Show All" should be */) {
//Create "Show All" cell
}
else {
//Create cell that contains info from filtered student fields
}
}
else {
//Your current behaviour here
}
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(searchMode && ![self.expandedStudents containsIndex:section] && /* indexPath corresponds to place, where "Show All" should be */) {
//"Show All" button pressed
[self.expandedStudents addIndex:indexPath.section];
[tableView beginUpdates];
/* For each row, that wasn't presented in collapsed student perform insertRowsAtIndexPaths:withRowAnimation: method */
[tableView endUpdates];
}
else {
//Your current behaviour
}
}

Related

Objective C checkmark row on viewDidAppear

I have a setting screen that is a UITableView with rows of settings. When user open that screen I load stored settings and filled to UITextField etc... Everything was fine.
But there are some of the checkmark settings, I've been trying to check this in programmatically way but is not work, here is my code:
-(void)viewDidAppear:(BOOL)animated{
[self LoadCurrentRecord];
if(_previousValid)
{
NSIndexPath *regionFromData = [NSIndexPath indexPathForRow:_regionAutoCheck inSection:3];
[self.tableView cellForRowAtIndexPath:regionFromData].accessoryType = UITableViewCellAccessoryCheckmark;
}
[self.tableView reloadData];
}
In fact, I can see data can load by check to this category but I didn't see checkmark icon.
Any idea?
You must need to set it in this method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell; // Create Cell
if(_previousValid && indexPath.row == _regionAutoCheck && indexPath.section == 3 )
{
// SET CHECKMARK
} else {
// SET NONE
}
}
Here is how you should work with table- and collectionViews:
Have a collection of dedicated data-elements for each of which a cell will be used to display its data. In your case this would be some kind of Region object.
Implement the table/collectionview datasource methods that return number of cells in section and number of sections based on that collection.
Make sure you configure each cell ONLY in -tableView:cellForRowAtIndexPath: / -collectionView:cellForItemAtIndexPath:, just like PKT's answer. This cell might be reused, so assume any changes you made to this type of cell you need to update here.
When data changes, create an indexPath for the object that changes based on its position in the collection from 1. Then call '-reloadRowAtIndexPath:'/ -reloadItemAtIndexPath for that object. This will cause the tableView/collectionView to call -tableViewcellForRowAtIndexPath:/-`collectionView:cellForItemAtIndexPath:' again. As this method now contains the logic for configuring the cell based on your data-object, everything is in sync.
I can't stress enough how important 1. is. Simplest example is: each section is an array of data objects. If you have multiple sections, you can add each array to another array:
// one section:
NSArray *myData =
#[
#[dataItem1, dataItem2, dataItem3]
#[dataItem4, dataItem5, dataItem6]
];
- (NSUInteger) numberOfSectionsInTableView: (UITableView *) tableView
{
return myData.count;
}
- (NSUInteger) tableView: (UITableView *) tableView numnberOfRowsInSection: (NSUInteger) section
{
NSArray *dataForSection = myData[section];
return dataForSection.count;
}
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath:
{
NSArray *dataForSection = myData[indexPath.section];
MyObject *dataObject = dataForSection[indexPath.row];
NSString * cellID = #"myCellID";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellID];
if (nil == cell)
{
// create a cell
// ...
}
// configure the cell based on the data object
if (dataObject.isBlue)
{
cell.contentView.backgroundColor = [UIColor blueColor];
}
else
{
// N.B.! don't forget the else clause, as cells are reused, so this
// cell might be recycled from a cell that was used to display
// the data of a blue data object before.
cell.contentView.backgroundColor = [UIColor blueColor];
}
return cell;
}
Finally, I've found a really simple solution for this case.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == _regionAutoCheck && indexPath.section == 3)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else{
cell.accessoryType = UITableViewCellAccessoryNone; // for other cases remove it
}
}
UPDATE
After that, add [self.tableView reloadData]; into -(void)viewDidAppear:(BOOL)animated and you will see it works.
That's all.
Thanks all for help

trying to create different cells in same table view - but can't figure out how to code in the tableviewcontroller

I have created a tableview with multiple prototype (4) cells in order to display different content in each cell but being a newb - I am not clear on how to then code this in the tableviewcontroller to pull data into the multiple cells (just using multiple simple arrays with one data point for each label for now to test it) but I can only get the data to populate in the first cell - and not clear how to code to get the data into the remaining cells. I created 4 separate customtableviewcell files as well. Can someone point me in the right direction on how to code so I can get data into the four separate prototype cells? I need it to be able scroll as it won;t all fit on the the screen which is why I chose table view to do this - but there will only ever be these four sections in the view (with different data depending on what you pushed to get here) should I not be using tableview? if I should be using something different like a view controller with 4 views instead? will it scroll so the user can see all sections? Thanks in advance for any help and suggestions.
You should assign unique Identifier to the each cell in the Storyboard. Then, you can populate appropriate cells like this:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section)
{
case 0:
{
MyCustomCell1 *cell = [tableView dequeueReusableCellWithIdentifier:#"cell_1"];
// Configure cell
return cell;
}
case 1:
...
default: return nil;
}
}
Consider creating custom subclasses of UITableViewCell to provide handy IBOutlets.
(1) You need 4 cells. So, prepare 4 custom cells by creating subclass of UITableViewCell. You will know how to create custom cell by search on google.
(2) Set number of sections to 1.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
(3) Set desired height for each cell
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch(indexPath.row)
{
case 0:
{
return 40;
}
case 1:
{
return 50;
}
case 2:
{
return 30;
}
case 3:
{
return 45;
}
default:
{
return 0; // Default case
}
}
}
(4) Set contents of each cell. The data will come from your data source i.e. Array or Dictionary.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:#"CellIdentifier%d%d",indexPath.section,indexPath.row];
if(indexPath.row == 0)
{
CustomCell1 *objCustomCell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(objCustomCell1 == nil)
{
objCustomCell1 = [[CustomCell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
objCustomCell1.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Set row specific data here...
NSDictionary *dicObj = [arrYourDataSource objectAtIndex:indexPath.row];
objCustomCell1.myLabel.text = [dicObj objectForKey:#"your key"];
return objCustomCell1;
}
else if(indexPath.row == 1)
{
CustomCell2 *objCustomCell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(objCustomCell2 == nil)
{
objCustomCell2 = [[CustomCell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
objCustomCell2.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Set row specific data here...
NSDictionary *dicObj = [arrYourDataSource objectAtIndex:indexPath.row];
UIImage *theImage = [UIImage imageNamed:[dicObj objectForKey:#"your key"]];
objCustomCell2.myImageView.image = theImage;
return objCustomCell2;
}
// Do same for remaining 2 rows.
return nil;
}
First do this and then add comment. We will move ahead.

Weird behaviour using 2 cell dentifiers in a tableViewController

I'm playing with the cell identifier in a TableviewController, I'm using storyBoard with dynamic cells.
I set 2 cells with 2 identifiers and used a custom row height:
In my viewDidLoad, I just insert some checking information to a mutableArray:
- (void)viewDidLoad
{
[super viewDidLoad];
_arrayCellContent = [[NSMutableArray alloc]init];
for (int i=0; i<15; i++) {
if (i%2 == 0) {
[_arrayCellContent addObject:#"white"];
}
else
[_arrayCellContent addObject:#"Brown"];
}
}
My cellForRow delegate method is:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* identifierCellSlim = #"cellSlim";
static NSString* identifierCellFat = #"cellFat";
UITableViewCell *cellSlim = [tableView dequeueReusableCellWithIdentifier:identifierCellSlim forIndexPath:indexPath];
UITableViewCell *cellFat = [tableView dequeueReusableCellWithIdentifier:identifierCellFat forIndexPath:indexPath];
if (indexPath.row%2 ==0) {
cellSlim.textLabel.text = self.arrayCellContent[indexPath.row];
return cellSlim;
}
// Configure the cell...
else {
cellFat.textLabel.text = self.arrayCellContent[indexPath.row];
cellFat.detailTextLabel.text = #"yalla";
return cellFat;
}
}
The final outcome is:
Even cell row heights, not costumed. Why is that? (I know I might work it out with the right delegate method, but I just want to know why the IB not doing his job)
Also in the beginning the cells appear to be in the right color but when I click some of them they will transform to the other cell,
Does clicking the cell change the indexPath ?
Example:
You are dequeuing both cells in the same method call.
You should check for which cell is necessary for the given NSIndexPath and dequeue the relevant cell.

How to do some action after selecting a section in a table view in ios?

In my app, I have a tableView, which contains 5 sections, each section contains only one row, I have inserted a customView on each row, The view consists of name and mobile number, when a section is selected, the name and mob. no. should of the "corresponding section" be passed to the next view.
I have inserted the screen shot below.
It seems you want to identify the section of the row for which didSelectRowAtIndexPath is invoked. You can get the section information in an NSIndexPath object itself by accessing 'section' property
Here is the class reference : https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSIndexPath_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
int section = indexPath.section;
//...
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//get the name and phoneNo from currently selected cell.
NSString *name = cell.yourCustomView.nameLabel.text;
NSString *phoneNo = cell.yourCustomView.phoneNoLabel.text;
if(indexPath.section == 0)
{
//code for section 1 selected
YourNextViewController *nvc = [self.storyboard instantiateViewControllerWithIdentifier:#"YourNextViewControllerIdentifier"];
nvc.nameProperty = name;
nvc.phoneNoProperty = phoneNo;
[self.navigationController pushViewController:nvc animated:YES];
}
if(indexPath.section == 1)
{
//code for section 2 selected
}
if(indexPath.section == 2)
{
//code for section 3 selected
}
if(indexPath.section == 3)
{
//
}
if(indexPath.section == 4)
{
//
}
}
You can use this logic.
1) According to your views, each section have phone no & Name. So you can keep into one array which contains dictionary object.like below
[
{
name : "Chandru"
phoneNo: "90xxxxxxxx"
},
..........
]
2) So you can use this in cellForRowAtIndexpath: as, cell.nameLabel.text = [self.yourArray objectAtIndex:indexPath.section] objectForKey:#"name"];
3) So you can pass it to next view as nextVC.selectedPersonDetail = [self.yourArray objectAtIndex:indexPath.section] in didSelectRowAtIndexPath:
where selectedPersonDetail should be public property of NSDictionary. Otherwise you can use public method to hold as private variable.

Search as-you-type from UISearchBar in a UITableView with multiple sections?

So I'm currently listening to a text change from the searchBar:
-(void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText
{
[self filterContentForSearchText:searchText];
}
I want to design a method filterContentForsearchText such that it automatically filters through my UITableView as I type.
The problem I'm having is that my UITableView is complicated. It has multiple sections with multiple fields. It's basically an contact/address book that is an array of arrays that holds contact objects.
CustomContact *con = [contacts[section_of_contact] allValues][0][x] where x is a specific row in that section returns a CustomContact "con" that has properties like con.fullName.
The UITableView currently displays fullNames of contacts in separate sections. How can I filter through this structure of an array/UITableView as I type using my UISearchBar?
Here's how the table is filled:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BrowseContactCell *cell = [tableView dequeueReusableCellWithIdentifier:#"BROWSECELL"];
CustomContact *thisContact = [self.contacts[indexPath.section] allValues][0][indexPath.row];
cell.labelName.text = thisContact.fullName;
return cell;
}
I also created an address-book with sections (an array of arrays), so I'll just post my solution, which is however not my own solution (I somewhere found it here on stackoverflow some time ago):
In your UITableViewController subclass just add the following two UISearchDisplayDelegate methods (link to the api reference) and the "custom" method filterContentForSearchText to filter through your array. For better understanding, please read my comments in the code blocks. Further questions or ideas for improvement are always welcome.
#pragma mark - search Display Controller Delegate
- (BOOL) searchDisplayController : (UISearchDisplayController *) controller
shouldReloadTableForSearchString : (NSString *) searchString {
[self filterContentForSearchText : searchString
scope : [[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex : [self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
#pragma mark - Search Filter
- (void) filterContentForSearchText : (NSString*) searchText
scope : (NSString*) scope {
// Here, instead of "lastName" or "firstName" just type your "fullName" a.s.o.
// I have also a custom NSObject subclass like your CustomContact that holds
//these strings like con.firstName or con.lastName
NSPredicate* resultPredicate = [NSPredicate predicateWithFormat : #" (lastName beginswith %#) OR (firstName beginsWith %#)", searchText, searchText];
// For this method, you just don't need to take your partitioned and
// somehow complicated contacts array (the array of arrays).
// Instead, just take an array that holds all your CustomContacts (unsorted):
NSArray* contactsArray = // here, get your unsorted contacts array from your data base or somewhere else you have stored your contacts;
// _searchResults is a private NSArray property, declared in this .m-file
// you will need this later (see below) in two of your UITableViewDataSource-methods:
_searchResults = [contactsArray filteredArrayUsingPredicate : resultPredicate];
// this is just for testing, if your search-Filter is working properly.
// Just remove it if you don't need it anymore
if (_searchResults.count == 0) {
NSLog(#" -> No Results (If that is wrong: try using simulator keyboard for testing!)");
} else {
NSLog(#" -> Number of search Results: %d", searchResults.count);
}
}
Now, you need to do some changes to your following three UITableViewDataSource-methods:
Note: the searchResultsTableView is also loaded with the normal common data source
methods that are usually called to fill your (sectioned address-book-)tableView:
1.
- (NSInteger) numberOfSectionsInTableView : (UITableView *) tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
// in our searchTableView we don't need to show the sections with headers
return 1;
}
else {
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count];
}
}
2.
- (NSInteger) tableView : (UITableView *) tableView
numberOfRowsInSection : (NSInteger) section {
if (tableView == self.searchDisplayController.searchResultsTableView) {
// return number of search results
return [_searchResults count];
} else {
// return count of the array that belongs to that section
// here, put (or just let it there like before) your
// [contacts[section] allValues][count]
return [[currentMNFaces objectAtIndex : section] count];
}
}
3.
- (UITableViewCell*) tableView : (UITableView *) tableView
cellForRowAtIndexPath : (NSIndexPath *) indexPath {
BrowseContactCell *cell = [tableView dequeueReusableCellWithIdentifier:#"BROWSECELL"];
CustomContact *thisContact = nil;
// after loading your (custom) UITableViewCell
// you probably might load your object that will be put into the
// labels of that tableCell.
// This is the point, where you need to take care if this is your
// address-book tableView that is loaded, or your searchTable:
// load object...
if (tableView == self.searchDisplayController.searchResultsTableView) {
// from search list
faceAtIndex = [self->searchResults objectAtIndex: indexPath.row];
} else {
// from your contacts list
contactAtIndex = [self.contacts[indexPath.section] allValues][0][indexPath.row];
}
}
Hope that works for you.

Resources