Original UITableView is shown over UITableView of the results using Search Bar - ios

I am adapting my App for support both iOS7 and 6.
I am using a Search Bar over a Table View for filter data to show.
But when my search is filtered, appear the table view with filtered data above the original data table view, so they are overlapped.
Does anyone have any idea?
Thanks in advance.
Attach 2 images:
Without search.
With search (as you can see, table view are overlapped)
Edited:
Adding Data Source methods
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return arregloFiltrado.count;
}else{
return arreglo.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"CeldaLista" owner:self options:nil];
cell = celdaLista;
self.celdaLista = nil;
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
[(UILabel*)[cell viewWithTag:1] setText: /*Name and surname*/];
[(UILabel*)[cell viewWithTag:2] setText: /*Other properties*/];
if ([[arregloFiltrado objectAtIndex:indexPath.row] objectForKey:#"photo"] == nil) {
[(UIImageView*)[cell viewWithTag:4] setImage:/*No image*/];
}
else{
[(UIImageView*)[cell viewWithTag:4] setImage:/*Photo*/];
}
} else {
[(UILabel*)[cell viewWithTag:1] setText:/*Name and surname*/];
[(UILabel*)[cell viewWithTag:2] setText:/*Other properties*/];
if ([[arreglo objectAtIndex:indexPath.row] objectForKey:#"photo"] == nil) {
[(UIImageView*)[cell viewWithTag:4] setImage:/*No image*/];
}
else{
[(UIImageView*)[cell viewWithTag:4] setImage:/*Photo*/];
}
}
return cell;
}
Something more?

If you use a UISearchDisplayController it has it's own UITabelview. So as you begin to search the search display controller superimposes the search interface over the original view controller’s view, as described here: https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchDisplayController_Class/Reference/Reference.html
You may want to set the background colour of the table cells or the entire table view for the table provided by the UISearchDisplayController so that is not transparent.
Alternatively you could filter your original table by implementing a UISearchBar and its associated delegate methods:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
//As the user enters search text filter the array that provides data to the UItableView you wish to filter
}
Investigate the searchbar delegate here: https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBarDelegate_Protocol/Reference/Reference.html
Thanks
TG

Try this code:
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView{
tableView.backgroundColor = [UIColor whiteColor];//color of search result table
}

Related

Single Array Value to show multiple tableview on one viewController

I am developing Iphone Application.Using Three table view on Single viewcontroller. value show on those tableview's on single array but problem is that those array value show on first tableview not on other two tableview's. please help Thanks in advance
code..
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_arrayResult count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"cell";
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
MEObject *obj = [_arrayResult objectAtIndex:indexPath.row];
if (tableView == _tableView) {
cell.textLabel.text= obj.emp_client_name;
}
if (tableView == _secondTableView) {
cell.textLabel.text= obj.emp_event_name;
}
if (tableView == _thirdTableView) {
cell.textLabel.text=obj.emp_client_name;
}
return cell;
}
Please cross check if you are setting datasource and delegates of all 3 tables to viewcontroller.
When you set your _arrayResult, you need to reload all 3 table view
_arrayResult = #[a,b,c];
[table1 reloadData];
[table2 reloadData];
[table3 reloadData];
After once you set the datasource/Delegate to the all three tableview. I haven't seen any datasource allocation as per your tableview. Like
if tableview == tableview1 {
Return first array
}
Can you please try giving name to those tableview on outlet and then for each datasource and delegates function call as per your requirement but before check which tableview is displayed.

how to use two tableviews using button

i want to use two tableviews like…..
i am using popover controller
first tableview is in the popover controller
in that popover controller i have two buttons(add notes button and remainder button)
when i click on the remainder button i am hiding the first tableview and enabling the second tableview
ut for the second tableview cellforrowatindexpath is not calling
only for the first tableview it is calling,not calling for the second table view
here my code is………..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==self.remainderTableView)//second Tbleview {
static NSString *cellIdentifier=#"Celliden";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=#"hhh";
return cell;
}
else if (tableView==self.NotesandRemainderTable)//first Tableview {
static NSString *cellIdentifier = #"bookingCell";
CustomTableViewSwipeCell *cell = (CustomTableViewSwipeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *note=[jsondata valueForKey:#"TeacherNotes"];
NSLog(#"teacher notes %#",note);
// if (cell==nil) {
// cell=[[CustomTableViewSwipeCell alloc]init];
// }
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:#"Delete"];
_SubjectLabel.text=AppDel.sub;
NSLog(#"the date %#",AppDel.date);
_DateLabel.text=_dateToDisplay;
if (indexPath.section==0)
{
if (indexPath.row==0)
{
cell.Noteslabel.text=note;
}
return cell;
}
if (indexPath.section==1){
cell.Noteslabel.text=[_notesArray objectAtIndex:indexPath.row];
//NSLog(#"notes index %#",[notesArray objectAtIndex:indexPath.row]);
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate=self;
return cell;
}
}
//cell.rightUtilityButtons = rightUtilityButtons;
return nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView==self.NotesandRemainderTable) {
if (section==0) {
return 1;
}
else if (section==1) {
if (leanerNots==nil || [leanerNots isEqual:[NSNull null]]) {
return 0;
}
else{
return [_notesArray count];
}
}
}else{
return 3;
}
return 0;
}
//This my remainder button code......
-(IBAction)addRemainderAction:(id)sender{
self.lineLabel.hidden=NO;
self.remainderTableView.hidden=NO;
self.addButtonObj.hidden=NO;
//self.remainderTableView.frame=CGRectMake(0, 62, 300, 321);
//[self.view addSubview:self.remainderTableView];
self.NotesandRemainderTable.hidden=YES;
self.notesBtnObj.hidden=YES;
self.remainderBtnObj.hidden=YES;
_SubjectLabel.hidden=YES;
}
Can any one help to solve this bug...i am new to Xcode
Did you set the datasource and delegate of your second tableview?
for example in viewDidLoad:
self.remainderTableView.datasource = self;
self.remainderTableView.delegate = self;
And you probably want to reload your tableviews before they are displayed. To do so use the following code for your second tableview
[self.remainderTableView reloadData];
It's not totally clear from this code whether you have set the delegate and dataSource correctly for both UITableView instances. If you have not, then these delegate methods will never get called.
Regardless, this case might be better handled by using two data sets instead of two tableViews. Implement cellForRowAtIndexPath the same way you are now, except instead of creating your cell conditionally based on the value of tableView, just use the value of your UIButton. Two UITableViews seems like overkill for this situation when the UITableViewDelegate and UITableViewDataSource methods allow you to source from different data sets easily already.

Core Data Cells not updating correctly

I have a problem with data being displayed in a UITableViewCell I have created.
I have a CoreData Model which I have a custom Cell which I am loading from a Xib. The layout loads correctly and the correct number of cells are generated. The problem comes when updating the button.titleLabel.text and description.
Here is my uitableview and uitableviewcell related code:
#pragma mark - UITableViewDatasource Methods.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [pointsHistoryItems count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:#"Cell%d",indexPath.row];
PointsHistoryItemCell* cell = (PointsHistoryItemCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return [self createCustomCell:cell cellForRowAtIndexPath:indexPath];
}
- (PointsHistoryItemCell *)createCustomCell:(PointsHistoryItemCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (cell == nil)
{
cell = (PointsHistoryItemCell *)[[[NSBundle mainBundle] loadNibNamed:#"PointsHistoryItemCell" owner:self options:nil] objectAtIndex:0];
}
AwesomePointsHistoryItem *aphi = (AwesomePointsHistoryItem *)[pointsHistoryItems objectAtIndex:indexPath.row];
cell.description.text = aphi.description;
NSString* pointsText = [NSString stringWithFormat:#"%# Points", [aphi.points stringValue]];
[cell.button.titleLabel setText:pointsText];
NSLog(#"is reaching createCustomCell");
NSLog(#"points %#", cell.button.titleLabel.text);
return cell;
}
the log prints:
is reaching createCustomCell
points 600 Points
However.. The cell.button.titleLabel.text does not update!
What am I doing wrong?
Use
[cell.button setTitle: pointsText forState: UIControlStateNormal];
instead of
[cell.button.titleLabel setText:pointsText];
Note : hope cell.button is a UIButton

UITableview grouped style only showing one value from array?

MY UITableview Group style only showing one value from the array of 4 elements.
in viewdidload i add following array
_displayThemeItems=[[NSArray alloc]initWithObjects:#"Default",#"Night",#"Sepia" ,#"Blue" ,nil];
_displayThemeIcons=[[NSArray alloc]initWithObjects:[UIImage imageNamed:#"day.png"],[UIImage imageNamed:#"night.png"],[UIImage imageNamed:#"sepia.png"], [UIImage imageNamed:#"blue.png"],nil];
and my table delegate methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_displayThemeItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=#"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// No cell available - create one.
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];}
NSLog(#"rray%#",_displayThemeItems);
cell.textLabel.text = [_displayThemeItems objectAtIndex:indexPath.row];
cell.imageView.image=[_displayThemeIcons objectAtIndex:indexPath.row];
return cell;
}
Your code look fine to me, the only the only reason that I can think amy effect the result you see is how you set up your table view.
Make sure that your table view frame is bug enough to show the 4 items, and make sure you set the tabe view data source.
Add the "}" just before the return such that the code where you set the title and image comes under the "if" statement.

iOS Popover and tableviewcontroller refreshing issue

I'm writing a project that simulates a Master/detail layout for iPad.
So i've a masterView(UITableView), a detailView(UICollectionView), a global Navigation Bar and a TabBar.
The tabbar is filled with some catecories i need to choose from and the masterview is filled according to the tabbaritem selected.
In landscape mode, when both master and detail view are shown, everything works fine.
In portrait mode, my master view is hidden and i've got a button that open a popupcontroller with my master in it. The problem is that this popup doesn't seems to show the changes made on the masterview content
the MasterView is a UITableViewController.
I've correctly implemented the delegate and datasource method.
Here is the code to open/dismiss the popover
if(myPopIsVisible)
{
myPop = [[UIPopoverController alloc]initWithContentViewController:myMasterView];
[myPop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
myPopIsVisible = YES;
}
else
{
[myPop dismissPopoverAnimated:YES];
myPopIsVisible = NO;
}
Checking in debug it lend me to the correct content of myMasterView (number and content of rows) but it only show the first one loaded by the app.
I'm using ARC...
This is myMasterView class implementation
#implementation myMasterView{
NSArray *cellTitles;
NSArray *cellIco;
NSArray *cellTag;
}
- (void) setData:(NSArray *)titles :(NSArray *)icos :(NSArray *)tags
{
cellTitles = titles;
cellIco = icos;
cellTag = tags;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
// Configure the cell...
cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
cell.tag = [[cellTag objectAtIndex:indexPath.row] integerValue];
#warning icona non impostata
// cell.imageView.image = [cellIco objectAtIndex:indexPath.row];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [cellTitles count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(isPopover)
{
isPopover = NO;
[master dismissPopoverController];
}
}

Resources