I have a UITable in order to search among some data (timezones). My problem is that when the overlay view comes up the index is still shown.
As shown in the image below the "?" character is shown and the index can be enabled. Is it possible to disable it when searching and the overlay is activated? How?
In sectionIndexTitlesForTableView return nil when your search bar is active.
Decrease your height of UITableView from the top
Do you use UISearchDisplayController?
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return (([[self.fetchedResultsController sectionIndexTitles] count] > 5) ? [self.fetchedResultsController sectionIndexTitles]:nil);
}
I show it when i have more than 5 results
Also this is a method of UITableViewDataSource. you need to implement and specify in header you implement ex :
UITableViewController<NSFetchedResultsControllerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
Are you refreshing the underlying tableview while the search table view is shown?
If you are, try to stop that. I had a similar problem which I was able to solve this way.
Related
I am using iCarousel in my application,I need to get the current index of the iCarousel and display that index in a label(subView of self.view) which is not a subView of iCarousel.
I am able to get the current index With
int index=iCarousel.currentIndex;
How can i update the index in label.text that every time when the carousel is Scrolled.
In which method i have to write the code to update label.
Whenever you scroll the following delegate will called, so you can update your label here
- (void)carouselCurrentItemIndexUpdated:(iCarousel *)carousel1
{
int index=carousel1.currentIndex;
yourlabel.text = [NSString stringWithFormat:#"%d",index];
}
For using the iCarousel, it is better to study its documentation thoroughly before going into its implementation from iCarousel Documentation.
So for the issue you are facing , there are 2 methods provided in the documentation -
- (NSInteger)indexOfItemView:(UIView *)view;
The index for a given item view in the carousel. Works for item views
and placeholder views, however placeholder view indexes do not match
the ones used by the dataSource and may be negative (see
indexesForVisibleItems property above for more details). This method
only works for visible item views and will return NSNotFound for views
that are not currently loaded. For a list of all currently loaded
views, use the visibleItemViews property.
- (NSInteger)indexOfItemViewOrSubview:(UIView *)view
This method gives you the item index of either the view passed or the
view containing the view passed as a parameter. It works by walking up
the view hierarchy starting with the view passed until it finds an
item view and returns its index within the carousel. If no
currently-loaded item view is found, it returns NSNotFound. This
method is extremely useful for handling events on controls embedded
within an item view. This allows you to bind all your item controls to
a single action method on your view controller, and then work out
which item the control that triggered the action was related to. You
can see an example of this technique in the Controls Demo example
project.
Hope this helps !! :)
A bit late, but for others, the following delegate method works for me (with multiple carousels)
- (void)carouselCurrentItemIndexDidChange:(iCarousel *)carousel
{
NSLog(#"%s", __FUNCTION__);
if (carousel == carousel2) {
NSLog(#"here");
long (or int) currentIndex = carousel.currentItemIndex;
}
}
As you see above, I have a Table View on LeftSide which contains a Some Text.
But when i selected any annotation in map according to that the cell will be Highlighted & it has more text rather than other Cell and also background color is changed.
How can i achieve this?
You can approach in following way.
First both table data and annotation pins in Map are filled from an array!!
What you can do, you can define "tag" as array index to particular item.
When a user tap on a annotation, that annotation has a "tag" (or array index) and this "tag" (or array index) also has an item for table data.
On click of annotation tap, you have to reload your table and make that particular tableview cell highlighted.
You need to customize the UITableViewCell for this
Add a table view and map view in your view as shown in figure.
Load the custom table view cell to tableview
Initially give the needed color for all table cells
When user selects a cell change it's color
Using didSelectRowAtIndexPath: delegate method show the corresponding value on map.
Check this link for tutorials:
Appcoda
The basic sample for slide menu in iOS
https://github.com/nverinaud/NVSlideMenuController
Hope this sample code will helps you
I think you are creating custom annotation instead of the default one so if it is possible for you to set tag for each annotation view which will be same as tableview cell index. While selecting an annotation create indexpath with that tag and set selectedrow for that indexpath. Hope it may help you.
Create your customized class of UITableViewCell.
Understand you have two conditions A. Normal Cell B. Cell after the click.
You'll have to use 3 delegate methods of UITableView to achieve this.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here you'll have to check for the condition you'll have to check which indexPath.row is selected. and according to that you'll have to change the height of your row.
return hight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Again the same thing. You'll have to check the condition and load the appropriate controls with appropriate frames.
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is the important function for you.
// Here you'll have to set one counter. Which you'll use in the
// After that reload the table.
}
I have an UITableView with sections and many rows.
I don't need a detailed search, going through all cells in the tableview.
All the sections titles are contained inside a NSMutableArray.
Is there a simple way to search only the sections titles of an UITableView, disregarding the cell contents?
Thank you!
you have to insert the uisearchbar on the head of the table. next you have to implement a method that search on the array with the titles and create a new array with the elements to show (titles and cells, they can also be two array, you have to choose basing on the normal app-workflow) and reload the table.
See this Apple Sample implementation - notice the function named:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
Here, instead of:
for (Product *product in listContent)
You can put:
for (NSString *sectionHeader in YourSectionArray)
Also change implementation of this function as per your need, you should be done. (like, you can ignore the scope things as you only want to search for section header which is nothing but a simple string) This function is simply search routine which you can change as you wish. It is actually called by following delegate function - this you do not want to change:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
Note that this control I am suggesting is an in-built tableview control that comes with search bar already. It is:
UITableViewController <UISearchDisplayDelegate, UISearchBarDelegate>
If you added search bar on your own, you would need to add both these delegates to your UITableView .h file like I did above. If you would rather copy Apple's example implementation, no worries.
I have a UITableview which shows 10 rows currently which is fixed static. Now I want to add a feature into it. I want to add a more 10 rows to the table when user reach to the last row of the UITableView. I mean currently I am showing fixed 10 rows in the application.
But now I want to add 10 more rows whenever user reaches to the last row of previous UITableview.
Please give me any suggestions or any sample code to achieve my motive. Thanks in advance.
It is actually quite simple. What you need to do is implement the tableView:willDisplayCell:forRowAtIndexPath: method, which belongs to the UITableViewDelegate protocol. This method hits every time a cell is about to be displayed. So, it will let you know when the last cell is about to be displayed. Then you could do something like-
– (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *) cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == [self.array count] - 1) //self.array is the array of items you are displaying
{
//If it is the last cell, Add items to your array here & update the table view
}
}
Another (a bit mathematical) option is to implement UIScrollView delegate methods (UITableView is a subclass of UIScrollView), namely scrollViewDidEndScrollingAnimation: or scrollViewDidScroll:. These will let you know the y-position of the content the user is viewing. If it is found that the bottom most content is visible, you can add more items.
HTH,
Akshay
uitableview is derived from uiscrollview. To achieve your objective, you need to implement scrollViewDidEndDecelerating:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
if (endScrolling >= scrollView.contentSize.height)
{
// your code goes here
}
}
This will detect a "bouncing effect" like shifting up the visible rows to indicate that one would like to see more.
How would you exactly want to invoke the loading of the additional 10 rows? When a user just scrolls down to see the first 10 that are loaded by default he might not want to load 10 more already.
You may add a "add more" line as the last row of your table. When the user clicks on this one you add 10 more.
(I don't know how one would detect a "bouncing effect" like shifting up the visible rows to indicate that one would like to see more.)
The basic logic would look like this:
in cellForRowAtIndexPath you check if the user clicked on the last line and then invoke your code to add the 10
to actually add 10 more lines you have to call [myTable reloadData]
but before you call you need to increase the returned value of numberOfRowsInSection by 10 and make sure that cellForRowAtIndexPath will correctly return your new lines 11-20
ps if you REALLY want 10 additional rows to be loaded when the user reaches the end of the table you need to invoke the loading of 10 more in cellForRowAtIndexPath or willDisplayCell:forRowAtIndexPath: when it is called for your last line.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [categoriesList count];
}
Here categoriesList is an array. We can add objects to this array and call reloadData in the tableview.
I designed a uitable view like in the image below , I want to hide the part under the second section , which I write on it (<- I want to remove this part ->)
any suggestion to do that
If you coppied the code from someone, this element is the fotter view for the second section. Look for the method:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
end erase it. It should be out.
You can try creating the table with specific height in the Interface Builder or:
UITableView* pTable = [[UITableView alloc] initWithFrame:(CGRect)];
Maybe you can also specify that scrolling is forbidden in order to show the contents that you want:
pTable.scrollEnabled = NO;
You might want to implement tableView:heightForFooterInSection: and tableView:heightForRowAtIndexPath: and return heights for the footer of the current section and header of the next section to reduce the gap between the two sections. This of course, if there are sections are the current section. If there are no more sections, then you can just reduce the frame size.