How to open a view with a button clicked as default - iphone

In my app i want to open a view with the content of a particular button (so that button should look clicked and should be not clickable). I have 4 button with pictures and all the four have different content inside them (Table view with different content).When this view gets open i want the first button clicked automatically and the content of that button should get displayed and by clicking any other button the content of that button should get displayed and the previous clicked button should be available to click again.
I am using different pictures for clicked and unclicked button.
Thanks,

Maybe this will help you
- (void)didClickButton:(id)sender {
UIButton *optionButton = (UIButton *)sender;
if(lastSelectedButton.tag!= optionButton.tag) {
optionButton.selected = YES;
//According to your needs enable or disable the button's interaction
}
Here lastSelectedButton should be an instance variable.

What you're describing sounds like a segmented control. Essentially the segmented control works like buttons on a tape recorder (dating myself, I know.) When you press Play, it stays down and can't be pressed again until you press Stop or FF or Rew, etc. (Ok, Stop doesn't really work that way, but the rest of the buttons do)
Unfortunately, I don't believe you can use your own images in a UISegmentedControl, but fortunately there's an open-source version that should work for you: https://github.com/xhan/PlutoLand/blob/master/PLSegmentView.h
Once you have the control in place you can change the content of your main view depending on the value of the segmented control. You can handle that in the UIControlEventValueChanged event

Keep a single selector for all the buttons something like
[btn addTarget:self action:#selector(templateSelected:) forControlEvents:UIControlEventTouchUpInside];
and make use of the tag to carry any index to the selector
[btn setTag:integer];
and if you want to keep track of previously clicked button then keep a global (id) and assign the current button address to the that id.
And if you want the first button to be clicked on load then call the function melodramatically during initialization of the first button.
[self templateSelected:firstButton];

Related

Show hint on touching the button

I want to display some hint to user when a user touches the button in iPhone native application, just like tooltip in web applications.
I have a large number of TextField that should be associated with info button to let the user know the detail description about the data captured in that TextField.
Can any one post steps to achieve this?
Agreed with Justin, but if you really had to:
Add an action to the UIButton that launches on the Touch Down event, e.g. UIButton * button = [[UIButton alloc] init]; [button addTarget:self action:#selector(doSomething:) forControlEvents:UIControlEventTouchDown];
Define the 'doSomething' action method as showing a custom 'tooltip' view anchored to the button location. The UIButton which was touched will be passed to the action method, from which you can access its location and so know where to anchor the tooltip.
If this all sounds laborious, check out "Is it possible to show a tooltip in an iOS app?", which links to CMPopTipView (https://github.com/chrismiles/CMPopTipView#readme), a useful package which will do it all for you. Haven't used it myself, though.
I'm not sure how to achieve this, but it sounds like a terrible User Interface idea for a mobile app.
I say that because tooltips in classic applications typically happen on mouse hover. Mobile interfaces don't have an equivalent gesture. When you touch a button, it's like a click.
If you look at most mobile applications that need to explain something to the user, it's usually done through visual elements that show up when the app loads (they'll point to different buttons, explain what they're for, and then go away after the first time the button is used).

UIButton to forward events & retrieve values according to UIButton

I have a for loop that displays 7 UIButton all with a method pointing to the same view ( for loop , thats why) .
What i want is that when for
e.g ,i click on button1 , the next view will display values that belongs to button1 .
and when i click on button2 , the next view (same view again) will display values that belongs to button2.
Any idea on how to work on that?
I have classes and appDelegate to store this values in it
Edit:
my UIButton is programmatically created, i cannot link IBAction to it. I think a few have mistaken about my question.
For that, When you are looping for button, at that time, give tag value to button. And create one method like below:
-(IBAction)buttonClicked:(id)sender{
int clickedTag = [sender tag];
}
inside that, you will get the Tag of button which is clicked. And you can do according to Tag.
Just set the tag while you are creating the buttons programmatically.
[button setTag:counter]; // if you are creating the buttons in For loop
Cheers.
It sounds like all these buttons probably have the same action, right? Give each button a different value for its tag property. The action can then look at the tag of the object that sent the message, e.g. sender.tag, to figure out which button was tapped. Use that information to figure out what data to display in the next view.
Simple. Set the tag value for all the buttons. Use the sender object to display the values accordingly in your view.

slider gallery with touch recognition

HI
i was following this example to create a slider gallery
"http://lievendekeyser.net/index.php?module=messagebox&action=message&msg_id=1351"
But i stuck at one point. what i am trying to do is, when user double tap on current image, it should navigate to another view, like to view B.
But i am not able to navigate and detect double tap on current image.
suggestions needed.
regards
you can find the number of tap in touch event. and when count of tap == 2 then you should write code for further movements.
else put all these images in UIButton and provide the IBActions to all the buttons and perform the action.
use following code
[ScrollViewFavButton addTarget:self action:#selector(FavClickButton:) forControlEvents:UIControlEventTouchUpInside];
ScrollViewFavButton.tag = i;
[ScrlViewFavorite insertSubview:ScrollViewFavButton atIndex:i];
insert button in the scrollview and perform action in FacClickButton:.
I think now you'll get your answer.

UIButton delayed state change

I have a UIButton subview inside of a UITableViewCell.
When this button is touched, the user must hold the button for about a half second for the button's image to change to the UIControlStateHighlighted image.
This means that if the user just taps the button as is usually the case, the highlighted state is never shown.
Why does this occur and how can I fix it?
I just encountered this problem and saw that this issue hadn't been closed. After screwing around for a while I found a fix for it.
Now you can fix this by turning off delaysContentTouches or unchecking the "Delays content touches" box on the tableview.
The only negative side effect is that the user won't be able to tap down on a button and initiate a scrolling gesture. However, if the user tries to scroll starting from anywhere that doesn't itself accept touches, the behavior should be the same as before.
The problem is that your UIButton is inside a UITableView. This means that the table view has to determine whether your tap is going to be a swipe or if it's just a tap intended for the button. The table view has to delay sending a message to the UIButton until it knows that the user doesn't intend to swipe and therefore scroll the view instead of pressing the button.
If you don't need a table view, get rid of the UITableView.
Up for David Hodge's answer.
I just want to add a way to remove that "only negative side effect", already described by David: if you start scrolling inside a UIcontrol in a UIScrollView with delayContentTouches=NO, scrolling doesn't work.
SOLUTION
Subclass UIScrollView (or UITableView as the original question) and override:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
Your UIControls inside UIScrollView/UITableView will change their state immediately on tap and the scrollviews will be able to scroll even if the touch starts on some UIControl. Works like a charm.
I just change the image from within the target action method:
[sender setBackgroundImage:[UIImage imageNamed:#"highlighted-image.png"] forState:UIControlStateNormal];
It changes the background image instantly.
Edit: completely re-written following a misunderstanding of the question
One way of thinking of a UIButton is as a shorthand way of setting up an area of the screen that can respond to various instantaneous touch events the response it makes is defined by UIControl's Target-Action system for delivering messages to other objects.
UIControlEventTouchDown sounds like the one you need to respond to. It will be triggered as soon as someone touches inside your button - this is what the "Contact Info" button in SMS does.
UIButton* myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
// SEt up title, frame etc
[myButton addTarget:self action:#selector(myButtonWasPressed) forControlEvents: UIControlEventTouchDown];
[myMainView addSubView:myButton];
Will send a -(void)myButtonWasPressed message to the object this code runs from (ideally you view controller). In myButtonWasPressed you can then add a new view or take any action you like. The SMS app pushes a view controller to display the contact info using a navigation controller.
If this still doesn't solve your problem, you're going to have to post some code in order to get more insight into what's going wrong.

pressing event in UIButton?

when i am pressing my UIButton ,(i did not release my mouse button),i want to change
title? i tried touchupinside through XIB.but it was called after i released my mouse button.
i tried both land also all states....?
[sButton setTitle:#"hai" forState:UIControlStateNormal];
[sButton setTitle:#"hai" forState:UIControlStateHighlighted];
The Control Events documentation will list all of the events you can subscribe to for controls (in this case, your UIButton). The one you want is UIControlEventTouchDown. But the problem with your requirement is that pushing the button covers the screen with the user's finger and I wonder whether changing the title will really be beneficial.