I seem to be having a problem with the titles in my application.
Let me describe what is happening here.
1) starts out good with the correct image
http://img262.imageshack.us/img262/5808/picture15b.png
2) still good after clicking a cell
http://img31.imageshack.us/img31/4440/picture13dvg.png
3) after hitting the backbutton previous title remains and the last one is gone
http://img150.imageshack.us/img150/5689/picture14ltq.png
4) however after scrolling up and down fast enough the correct view appears again
http://img262.imageshack.us/img262/5808/picture15b.png
As you can see in the images above I'm using a UITableview however I'm NOT using the navigationItem title , I'm using a UILabel ( called title ).
When I click on my cells and scroll through my application everything is fine however when I click my backbutton, which is also not a standard backbutton from the tableview, but a UIBarbuttonItem it just pops the last view (and does some other stuff too)( the button below as seen in my imagelinks).
-(void)back_clicked:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
....
}
It appears that my Titles do not refresh when I press the back button(which makes sense I guess since i do not have some sort of a refresh function ).
I concluded this because when I scroll down really fast my original title comes back.
I noticed but could be wrong , bear with me here , that reloadData applies mostly to table ,cell constructing and such so I assume this is not the one I'm looking for.
So is there some sort of refresh function I can use ?
I would really like some suggestions ;)
thnx all for reading
If when you h it the back button you are coming back to another viewController i would suggest looking at the method viewWillAppear from UIViewController, you can override this method and call it before you go back, in the method implementation you can set the correct title ...reference http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/viewWillAppear:
How are you inserting the UILabel that you use as a title?
Like this: [self.navigationController.navigationBar.titleView = < label >];
or more like this: [< top window > addSubview: < label >];
I've never had any problems with custom title views using the first method.
Related
I have several views where I want the search bar to be hidden unless the user scrolls it down to use it. I use this command to achieve this:
[self.tableView setContentOffset:CGPointMake(0, 44) animated:NO];
This works ok, but it's not ideal; any time something happens that causes the table view to reload, it has to be repositioned again.
Now I have a view where I want to completely hide the search bar from the user, meaning they can't even scroll down to get to it, but I want to keep the scope bars at the top of the table. So basically I want to scroll the search bar off the top of the view and keep it there, while leaving the scope bar portion of the control visible. setContentOffset isn't doing it for me anymore, since the user can easily undo it.
Is there an approach to this that I'm overlooking?
Thanks in advance!
Update: I never figured this out, so ultimately I changed my design.
Although it's probably a bit late, when you say "any time something happens that causes the table view to reload, it has to be repositioned again", are you saying that every time your UITableView reloads it scrolls to its top? This isn't the standard behaviour of a UITableView.
In regards to the second part of your question regarding your UISearchBar's scope, I'd strongly recommend replacing the UISearchBar with your own UISegmentedControl (that's all the scope of a UISearchBar is anyway), so that the user isn't confused by there being an off-screen UISearchBar that doesn't do anything.
I have modified the code of Apple's sample iOS project TableSearch in order to use it for searching a webservice by parsing its contents. Everything I have implemented works fine except for one ugly detail when performing a search using the SearchDisplayController's SearchBar. I have changed the behaviour of the SearchDisplayController to make it call my search function first when the "Search" button was tapped.
The problem is that when the search iteration (which is performed in the background in an NSOperationQueue) is finished the "searchResultsTableView" (of the searchDisplayController) is not automatically displayed or not assigned the resulting content. If you then change the SearchBar's text or tap the "Cancel" button from the view which appears when you touch the search field (see TableSearch) the correct TableView appears with the search results. I simply want to have this step to be executed right after the search operation is finished, so before you interact. At this stage the "No Results" label is currently displayed. The methods "filterContentForSearchText" and "shouldReloadTableForSearchString" are unchanged from the original TableSearch project.
I have taken a look at different class references of the SearchDisplayController and its attributes but I could not find any final solution yet.
I have tried the following in a section which is definitely iterated after the NSOperation is finished but it does not seem to solve the problem.
[self.searchDisplayController.searchResultsTableView removeFromSuperview];
and
self.searchDisplayController.searchResultsTableView.hidden = YES;
These operations both have the correct view I want displayed BUT scrolling is disabled until you change the state so that the view is hidden again. It is possible to select TableView cells, though. I basically want to have this just with scrolling enabled...
Thanks in advance for your effort!
I have same problem and I just solved it. I had exactly same problem, I wanted disable instant search and when I hit search button, the table didn't load but when I clicked cancel, it loaded up. And If I scroll on table view that didn't load correct result after search, it crashed due to index out of bound.
The thing you need to do is reload searchResultTableView not current tableview. After you filter out your data by search term, put
[self.searchDisplayController.searchResultsTableView reloadData]
to reload your search result, and it will shows up after you hit search button.
Hope this help
I found that setting the searchBar.text causes searchDisplayController.searchResultsTableView be added to self.view, I solve it like this:
self.searchBar.text = #"xxxx";
[self.searchDisplayController.searchResultsTableView removeFromSuperview];
I'm trying to implement a UISearchBar within a UITableView, which behaves like the one in the "Artists" tab of the iPod application.
I have it hiding the navigation bar, and resizing the search box to show the "Cancel" button, etc. but am unable to get it to hide the section index titles.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
inSearchMode_ = YES; // tell sectionIndexTitlesForTableView: to return nil
tableView_.scrollEnabled = NO; // works correctly, var is definitely wired
[tableView_ reloadSectionIndexTitles]; // doesn't call sectionIndexTitlesForTableView:
...
Am I missing something? Is UITableView -reloadSectionIndexTitles broken?
Typically my response to this kind of thing would be to call reloadData, but that has the side effect of causing the UISearchBar to lose focus.
I think approach you want is along these lines (Say you have a ArtistController which you want to make searchable):
Add a sub-controller to the ArtistController called ArtistSearchController
When the search box is clicked, bring the ArtistSearchController to the front as modal (to hide artists) or add transparency if you still want to show artists in the background.
When a search term is entered, created a model for the ArtistSearchController which is the data from ArtistController, filtered using the search term, and then display it in a list view
close the modal view when the user hits cancel.
This will save you from manipulating your original controller/nav bar and give it better usability
It seems what I need to do is to use a UISearchDisplayController rather than hand-rolling my own. I was able to modify the "TableSearch" sample to use sections and section headings, and it behaves as I want it to.
I have a UITableViewController subclass. I set self.editing = YES at the end of the viewDidLoad method, but when the table is displayed the little red 'delete' icon does not appear next to each row.
Then, I added an edit button to the navigation item:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
When I launch the application now, it starts in edit mode (I can tell because the edit button says 'done') but, again, the delete icons don't appear. Then if I toggle it with the edit button twice (once to turn it off, then once to turn it on), the red delete icons appear.
So, my question is: why aren't the table cells displaying correctly when first displayed? I've tried moving the self.editing = YES line to other places in the code, like in the init function or the viewWillAppear function, but no dice. It seems like this is a result of funny ordering somewhere (e.g. table cells initialized before editing is set, or something), but I can't figure it out; running the debugger shows that the viewDidLoad call happens before cellForRowAtIndexPath, as one would expect.
Other notes:
Yes, I am having editingStyleForRowAtIndexPath return UITableViewCellEditingStyleDelete. But from debugging I've verified that that function is not even called after the first load. (It gets called after I toggle editing mode twice.)
d'oh, adding it in viewDidAppear (or, better: viewWillAppear) did the trick. Thanks #lukya and #willcodejavaforfood for suggestions.
I feel silly. I swear I thought I'd checked that.
Moral of the story: setting the editing property too early makes page elements not display in editing mode. (Doesn't that seem like a bug?)
Try using the
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
method in UITableView
Trying to move the position of the back item on the UINavigationBar by getting a handle to the backbutton however I only seem to be able to make it disappear rather than do anything with it
I have the following in viewDidLoad
self.navigationItem.leftBarButtonItem.title =#"Testing";
self.navigationItem.backBarButtonItem.title= #"1234";
They do not work however
self.navigationItem.hidesBackButton = YES;
Works as you would expect, looking through the documentation it looks like higher up the backItem might be readonly is this the case?
self.navigationController.navigationBar.backItem; // readonly
Any pointers on how to move this in approx 30 pixels much appreciated!
I don't believe this is possible. However, you can define a custom button (with back functionality) and place it wherever you want on the nav bar. Then simply hide the back button