ios-Update multiple UIViews on UIScrollview - ios

I have a ViewController that contain a UIScrollView, that contains a few views which are custom UIViews (very simple uiimage + uibutton) that the user can scroll between (one custom view at the a time).
I want the user to be able to "mark" a photo, and then to display a certain text, when the user select a different photo (by using the button), I want to update the text on the previous selected photo and the current selected.
What should I do?
Inside the view itself I don't have access to the previous view, I figured I should send a notification to the view controller but than I have no access to the button I want to update

You could use tags to identify the scrollViews subviews.
Add a tag to the subview and the same tag to the button that belongs to the subview while adding them to the scrollView.
view.tag = 1;
button.tag = 1;
Then in the method called by the buttons, you can use the buttons tag to get the according custom view.
-(void)buttonClick:(id)sender{
UIButton *btn = (UIButton*)sender;
NSInteger tag = btn.tag;
UIView* customView = [self.scrollView viewWithTag:tag];
}
To access the prevoius selected view, store the tag of that view when editing for the next call of the function.

Related

How to get index of multiple scrollview in iOS

i have horizontal and vertical scrollview, for example one scrollview have four button and and second scrollview have six button and more so, when i click on any button then got index of last scrollview view, i already using tag.
my problem is for example i click on third scroll then i want both tag
third scroll tag and specific button tag.
first tag of scrollview in storyboard .
set tag to button dynamically.(while create button or add button to scrollview)
track your index as below :
- (IBAction)clickonbutton:(UIButton *)sender {
UIScrollView* yourscrollview = (UIScrollView*)[sender superview]; // track your scrollview as per your view hierarchy
NSLog(#"%ld",(long)yourscrollview.tag);
NSLog(#"clicked button tag%#",sender.tag);
}

Two clickable items in UITableView

I have a UITableview as a contact list in which there are a lot of users. It has a thumbnail photo and profile details on each row. I want to make it like when clicking on thumbnail, it goes another page for photo and when clicking on the rest of the space it goes to somewhere else. By using table view delegate I know which row is clicked and pass data, like user id to a new ViewController. But can I know which row when the thumbnail is clicked?
I am using the tag to find the view from cell, like
UIImageView *thumbnailView = (UIImageView *) [cell viewWithTag:1];
I think I cannot label the row index by tag.
You can add gesture to thumbnail image and get events on it. Need to set tag for thumb image as per indexPath.row.
Add following code in you in cell datasource method (cellForRowIndexPath:) :
cell.YOURIMGVIEW.userInteractionEnabled = YES;
cell.YOURIMGVIEW.tag = indexPath.row;
UITapGestureRecognizer *clickable = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(imageClicked:)];
clickable.numberOfTapsRequired = 1;
[cell.YOURIMGVIEW addGestureRecognizer:clickable];
[clickable release];
And also used below method :
-(void)imageClicked:(id)sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
NSLog(#"image tag is = %d", gesture.view.tag);
////////
You custome come goes Here !!!!!!!!!!!!!!
///////
}
You can use the photo as accessory view. Or use a UIButton with the photograph as background and set the action accordingly. (e.g. call a method on the view controller which then performs the push or segue. Doing so you will have to pass some data to the view controller indicating which row was actually clicked in. The number of the row can be used or you can set the tag of the button with some numeric id.)
Go the Easy way because doing it hard-way won't grant you a president award, right ?
Instead of UIImageView take a UIButton and set the Image on UIButton instance.
Set Button tag as the indexPath.row so that when you retrieve it you know which row is clicked. You can also sort it the other way but it seems quiet handy.
Add target into the button to a custom function. [ btnObj addTarget ...... ]
tyepcast you sender to a UIButton and receive the tag (indexpath.row)
You can remove all gesture recognizers and buttons in tableviewcell, and in your controller, you can implement below delegate;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
To make this method triggered, you need to set tableview delegate as your controller, either via code as below, or using storyboard.
- (void)viewDidLoad {
self.tableview.delegate = self;
}
By doing this, it won't matter which item you clicked in your cell, delegate method will be called always.
I hope this helps.

Overlap iOS components viewController

I have a UITableView in my View Controller and I would like to place two buttons (one on the left and other on the right side of the UITableView), overlapping this component.
How would I do this? If I place a button in one of the sides, the UITableView shrinks to fit the new button, but I'd like to view it over the table.
Create the button as a subview of the view controller's view (this is easiest to do in code, because interface builder would automatically add the button as a subview of the UITableView
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(40,40,80,80)]; //Whatever your need and repeat for your second button
[self.view addSubview:button];

Hiding a delete button when you tap outside the view

I have a delete button that shows up when I swipe left on a table view's row.
I want to be able to hide this button if the user taps anywhere else in the view. How do I do that? I tried putting a giant button on bottom of all views but the tap outside is not being detected by the button.
In the viewDidLoad, I added the view controller as a target:
[self.backgroundButton addTarget:self action:#selector(backgroundButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
And in the callback I just have a message:
- (IBAction)backgroundButtonTapped:(id)sender {
NSLog(#"BACKGROUND VIEW TOUCHED");
}
But when I tap outside in a general area, I do not see the message.
I resolved the issue as follows:
. Created a view TopView subclassed from UIView
. Changed class of my top level view to this class.
. Within my logic at the proper place, stored the subview that needs to be hidden in the top view
self.view.mySubview = subview;
. Overrode hitTest:withEvent in top view. Here I detect the tap outside that of the subview and hide the subview as required.

How to Show popupViews

I have UiView,In my Uiview I have one Button And one textField.
When I click the button i need to show the popUp for date values.
when i click the textfield,other popUp with Names.If user select any name from there,that name will show in textfield.If User click on Button,Dates will be arranged by Ascending or Descending order.
Probelm is,My Uiview contain one Main table also.
Now how to differentiate that main table and popUp views.
Thanks.
Create your other popups as separate classes, and add them to your view when needed.
Example:
Create a class called "Names" which inherits from UIView or UIViewController
Create a class called "Dates" which inherits from UIView or UIViewController
To present any of those classes as a popup, you have 2 options:
In case you used UIView, then you can present them with [self addsubview:nview] & [UIView animationwithduration] to make the popup animation.
In case you used UIViewController, just use [self presentViewController:nview].
Each view will have tags, use them.
tableView.tag = 1;
textBoxView.tag = 2;
alertView.tag = 3;
Now that you have the tags you can differentiate the views with respect to the tags.

Resources