Sometimes we need to enable touchBegans on UITableView instead of didSelect method but
we are not able to do it.
So here we make a custom protocols methods to invoke touchesBegan and touchesEnded methods using Category files.
Follow the steps to do so:-
1)Within your project , Go to File Menu ->File -> New and click.
2)It will show dialog having two segments that is IOS and OS X . Withing IOS , select Cocoa Touch.
3)After that , click on "Objective-C category" option and go next.
4)It'll display another dialog having two options with Input Fields that is "Category" and "Category On".
5)Give TouchGesture as Category and select UITableView in Category On option and go next and click create button.
6)It will create two Files named UITableView+TouchGesture.h and UITableView+TouchGesture.m
Now we have created category files successfully, and further we will work on custom protocols to UITableView delegate.
In header File , create a protocol named MyCustomDelegate subclass of UITableViewDelegate and write two methods within it like given below:-
@protocol MyCustomDelegate <UITableViewDelegate>
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event;
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end
and Within Interface write a method to invoke custom delegate like
- (id<MyCustomDelegate>) customDelegate;
Now your header file would look like
In Implementation File , define interface method and call delegates on touchBegan and touchEnded gesture methods as given in the file.
At last we made it , now you can use it by importing UITableView+TouchGesture.h file in the place wherever you want to use this new delegate method that will invoke on the touchBegan and touchEnded of tableView.But keep in mind by implementing these methods didSelect method will not work.
write this tableView protocol in your viewController and perform your task within it.
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
//do your stuff.
}
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//do your stuff.
}
we are not able to do it.
So here we make a custom protocols methods to invoke touchesBegan and touchesEnded methods using Category files.
Follow the steps to do so:-
1)Within your project , Go to File Menu ->File -> New and click.
2)It will show dialog having two segments that is IOS and OS X . Withing IOS , select Cocoa Touch.
3)After that , click on "Objective-C category" option and go next.
4)It'll display another dialog having two options with Input Fields that is "Category" and "Category On".
5)Give TouchGesture as Category and select UITableView in Category On option and go next and click create button.
6)It will create two Files named UITableView+TouchGesture.h and UITableView+TouchGesture.m
Now we have created category files successfully, and further we will work on custom protocols to UITableView delegate.
In header File , create a protocol named MyCustomDelegate subclass of UITableViewDelegate and write two methods within it like given below:-
@protocol MyCustomDelegate <UITableViewDelegate>
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event;
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end
and Within Interface write a method to invoke custom delegate like
- (id<MyCustomDelegate>) customDelegate;
Now your header file would look like
In Implementation File , define interface method and call delegates on touchBegan and touchEnded gesture methods as given in the file.
At last we made it , now you can use it by importing UITableView+TouchGesture.h file in the place wherever you want to use this new delegate method that will invoke on the touchBegan and touchEnded of tableView.But keep in mind by implementing these methods didSelect method will not work.
write this tableView protocol in your viewController and perform your task within it.
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
//do your stuff.
}
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//do your stuff.
}
No comments:
Post a Comment