Hiding a UIView - objective-c

I have several UIViews that are on my xib file and would like to dynamically hide them when I want. I have the following code below but for some reason it's not hiding them. Any ideas what I could do?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//hide all the static UIviews
_searchBox.hidden = YES;
_searchButton.hidden = YES;
_logo.hidden = YES;
NSLog(#"FIRED THE EVENT");
//TODO: create a new view that holds a zoomed in image
}

Are theses items IBOutlet connected to the ones in your nib file? And are the referencing outlets linked? That is usually the cause.

Related

How reorder row in customize UITableViewCell

So far I have customized my UITableViewCell with the icon reorder row.
I want my cell can be reordered when long press on the reorder icon and then move it.
The image below is what I have expected.
I have read many document they provided only long press on cell and move it but I don't want it because long press on cell I have my another gesture is renaming it; and also I don't want to use the edit/done of UITableView default from OS; so I decided to put reorder icon but I can not do, because I'm new in objective c.
Can anyone help by providing sample code here?
Thank for reading.
Override two methods of UITableViewDataSource
For reordering to work you will first need to bring the Table in editing mode. Which you can either do it from viewDidLoad or from a IBAction method.
-(void) viewDidLoad{
[super viewDidLoad];
self.myTableView.editing = YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{
//Manipulate your data array.
}
By Default editing style is UITableViewCellEditingStyleDelete. So if you don't override the below method it will show both rearrange as well delete icon.
-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Since, you have long gesture of your cell causes issue with the long gesture of the re-ordering of cell. You can add a UIView to the cell. Add all your elements in this UIView. Now, attach a UILongPress Gesture to this UIView (not to the cell.).

Customization tableView

How I can add a bar with 3 UIButtons above a UITableView? Please, I need examples. I want to make it like this.
You can create a cell in your storyboard that contains a segment controller on it.
Now in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
You can dequeue that cell for the first on in the table.
In your viewDidLoad, create a UIView with a clear background colour.
Then, create a UISegmentedControl and add that as a subview to the clear view.
Finally, set your clear view as the table header view:
self.tableView.tableHeaderView = myClearView;
Bar is called as segmented control in iPhone.
To create it sub class UIViewControl class and add segmented control on top and then add UITableView below that better you can use Xib or you can find Coordinates and add both controls programatically.
refer to this link
you can do by implementing Header View Section delegate methods for your UITableView in your ViewController
In the following delegate method, give the size of your view you want to implement
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 60.0f;
}
Implement UISegmentedControl to get your three buttons and implement that in your viewForHeaderInSection method
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segments] autorelease];
segmentedControl.frame = GRectMake(60, 10, 200, 40);
........
// Do other Stuffs of Segmented Control
........
return segmentedControl;
}

How to save state of UICollectionViewCell

Please help me, how can I save state of UICollectionViewCell. For example: I have cells with UIWebView and when I dequeueReusableCellWithReuseIdentifier:forIndexPath: returned wrong cell, not for this indexPath and after it UIWebView content will reloaded for correct indexPath with twitches. Thanks!
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NewsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"NEWS_CELL" forIndexPath:indexPath];
if (!cell.isShowed) { // I just added boolean property
cell.isShowed = YES;
/*** some init actions ***/
}
return cell;
}
If I use this method, cells with cell.isShowed == YES return on wrong indexPath. But if I not use cell.isShowed content of UIWebView will reloaded in every showing cell
Sorry for my english :)
See what Apple's UIWebView Class Reference say:
Important: You should not embed UIWebView or UITableView objects in
UIScrollView objects. If you do so, unexpected behavior can result
because touch events for the two objects can be mixed up and wrongly
handled.
But UICollectionView inherits from UIScrollView. So you need to redesign your architecture.

UISearchBar in UIView

I'm having difficulty following directions. I have a UISearchBar in a UIView. The user will enter the search string into the UISearchBar and click the search icon to search. The results will display in a new window (UITableView).
My search has shown me this:
A UISearchDisplayController cannot be added to a UIView because it
doesn't inherit from a UIView. You can add a UISearchBar in Interface
builder with an IBOutlet and then create a UISearchDisplayController
with that UISearchBar programmatically.
Just do it in code e.g. (assuming the view controller is vc): [vc
addSubview:mySearchDisplayController.searchBar]; // Note that
searchBar is the view, and mySearchDisplayController only CONTROLS the
searchBar etc.
and also this:
Just make your view controller implement the UISearchBarDelegate. In
your xib file, all you need to do is to add a UISearchBar to your view
and configure it as necessary, create an outlet for it (optional
really but helps to be explicit), and assign the delegate outlet to
your view controller. Then, to respond to the search bar events,
implement the UISearchBarDelegate protocol methods as necessary. For
example:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[self handleSearch:searchBar]; }
(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
[self handleSearch:searchBar]; }
(void)handleSearch:(UISearchBar *)searchBar {
NSLog(#"User searched for %#", searchBar.text);
[searchBar resignFirstResponder]; // if you want the keyboard to go away }
(void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
NSLog(#"User canceled search");
[searchBar resignFirstResponder]; // if you want the keyboard to go away }
I'm just not getting it! Should I be adding mySearchController to my UIView? or my UISearchBar? Adding it to my UIView, nothing happens; adding it to my UISearchBar really wigs out the application. I don't even get an error - it just hangs.
Then, there is the second part: The delegate. Should I put the delegate in my UIView? Or in the UISearchDisplayController? Not sure which direction to go in and nothing so far is working. Please help.
All I really want at this point is just to get the handleSearch method to get executed. Thank you very much in advance for any help.
Very confused.
The idea is that you create a Search Bar in Interface Builder as an outlet and then use the following code to create UISearchDisplayController:
self.searchDisplayController2 = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchDisplayController2.delegate = self;
self.searchDisplayController2.searchResultsDelegate = self;
self.searchDisplayController2.searchResultsDataSource = self;
This code would be implemented in your View Controller, say in viewDidLoad. You will also have to implement at least two delegate functions in the same VC:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

UITableView custom section header disappear

I have a view that I'm trying to use as a header section of my UITableView.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *name= (UILabel *)[myView viewWithTag:200];
name.text = #"title";
myView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"row-bg-red.png"]];
return myView;
}
It loads ok, but when I scroll down and the next header appears, the previous does the opposite: it disappears.
Any suggestion?
I guess you reuse the one view. This is not possible. Each view (UIView subclass) can be in the view hierarchy exactly once. So what probably happens in your case is that when you set the second section view, it gets removed from its original place where you put it last time for the first section.
You can create every time a new section header view directly in - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method.