How to catch event of pressing TableViewCell? - iphone

I have question for you ...
I have UITableView and I want to catch event when user press the cell in order to change the color of label that I insert into UITableViewCell. The moment when user touch the cell.
tableView:willSelectRowAtIndexPath:
tableView:didSelectRowAtIndexPath:
functions didn't help me ...
Who have any suggestion ? Thanks a lot for help !!!

If you want to change the color of a UILabel inside a UITableViewCell when it's selected, you don't have to do any sort of event catching. You just have to change the highlightedTextColor property of the UILabel. The default is usually white.

Subclass the UITableViewCell and override the UIResponder with these:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
Then you will have 2 separated events when press and when release.

Did you set the delegate of the tableView?
Did your class conform to the UITableViewDelegate protocol?

Confirm With UITableViewDelegate protocol and implement the methods which you mention,
Do'nt forget to set the delegate property of your UITableView.
myTableView.delegate = self;

Have you looked at UILongPressGestureRecognizer? See: http://developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UILongPressGestureRecognizer

Related

How to dismiss the iPhone number pad?

Is there any simple method other than the one seen in
http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key
to dismiss a Number pad in iPhone??
This code for a single text Field seems a lot.!!
You can also do this by casting the background view to be a UIControl and then hook up a touch event to the controller's [self.view endEditing:YES];
You do this by changing the class of the base view in the xib to to be a UIControl instead of UIView
This means that the keyboard can be dismissed by touching the background.
HI Finally from all the suggestions i Got it!!
Make your keyboard as Number Pad on Xib and put the following code in the .m file after connecting all the textFields..
-(void)touchesBegan NSSet *)touches withEvent UIEvent *)event
{
[txt11 resignFirstResponder];
[txt22 resignFirstResponder];
}

Tapping a UIScrollView to hide the keyboard?

I'm working on an iPhone app which involves typing stuff into a UITextView, which adds content to a UITableView. The problem is, I need to be able to close the keyboard when the user's done with it, and the only area that is really visible other than the keyboard and UITextView at this point is the UITableView. I'm having trouble implementing a touch event on the UITableView (as in, touching the UITableView anywhere, not just didSelectRowAtIndexPath:). Here's the code I'm using in the view controller, which doesn't do anything at all:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[textView resignFirstResponder];
}
Any suggestions?
That looks like correct code to me. Put a breakpoint in to make sure it's being called.

How to Identify a touch/tap on an iPhone screen

I need to know which method is used to identify tap/mouse click.I
know
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {}
which are triggerd when cursor moved.
But I want to do following things-
I have an image.
When i will click it, similar two image will be created.And so on
Can anyone help????Advanced thanx for your reply.
The tap events are handled not by the touches method callbacks in UIView, but as targets-actions in UIControl. UIControl is a subclass of UIView, and adds abstractions for taps, drags and other common user actions, so that you do not need to implement the logic yourself.
To add a action for the user tapping a control simply do this:
[myControl addTarget:self
action:#selector(didSelectFoo:)
forEvents:UIControlEventTouchUpInside];
This is usable both if you subclass UIControl yourself, or if you use any of the provided controls such as UIButton, UITextField, UILabel, etc.

View as first responder

Hi all i want to know how to make subView added to content view of cell to become firstResponder.When i touch cell tableViewDidSelectRow methods get called.I have added customView as subView to cell.I have implemented delegate method which gets called when toches in custom view gets ended.But this method gets called after tableViewDidSelectRow method is called.I want first the delegate method to get called and then tableViewDidSelectRow .I have even set customView excluiveTouch property to YES.
Definitely ,
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
will called after DidSelectRowFor . Because didSelect called as we click the cell and touchesEnded after when we removing the finger.
if u want touchesEnded must called before DidSelectRowFor than you have to override the some method. like
(BOOL)becomeFirstResponder in cell class as well as in custom class properly. also override
(UIResponder *)nextResponder this method to call next responder.
try once this . and let me know whether working or not?

Recognize regular taps in table view on iPhone

I have a table view with custom cells and I recognize swipes in that cells. That works just fine but I'd like the table view to behave normally. When I tap the wherever on the table view I'd like cell to get selected and perform action tableView:didSelectRowAtIndexPath:
Any tips or ideas?
Thanks.
I assume you are implementing the various UIResponder methods in your UITableView cell subclass. If you want the rest of the stack to continue processing the events you can just pass them on:
- (void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
//do something with touch
//...
//pass the event to super which cause it to continue along the chain as
//though you didn't do anything special with it
[super touchEnded:touch withEvent:event];
}