UIButton inside UITableViewCell steals touch from UITableView - ios

I have a problem similar to this one but answer provided there doesn't help much.
I have UITableView with some custom UITableViewCells, those cells have some nested custom UIViews and finally some UIButtons inside. The problem, as in question specified above, is that when I touch my button touch event won't populate to UITableView and it never scrolls.
Here's some code (it's just fastest way to reproduce, it's not my actual code):
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (strong, nonatomic) IBOutlet UITableView * tableView;
#end
#implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,
self.view.bounds.size.width,
self.view.bounds.size.height)
style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[UITableViewCell alloc] init];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor redColor];
button.frame = CGRectMake(0, 0, 50, 44);
[cell.contentView addSubview:button];
return cell;
}
#end
Red button in the only cell won't let table view to bounce scroll.
Can anyone help me a bit?
P.S. Don't pay attention to the stupidity of the code I've provided, I'm aware of all issues about it. I just provided it to show what the issue is all about. It's the conflict of buttonView and scrollView.

You can change the behaviour by overriding touchesShouldCancelInContentView: in the UITableView. For this to work you'll need to replace the table view with this subclass, either in loadView or in your xib file.
#interface AutoCancelTableView: UITableView
#end
#implementation AutoCancelTableView
//
// Overriding touchesShouldCanceInContentView changes the behaviour
// of button selection in a table view to act like cell selection -
// dragging while clicking a button will cancel the click and allow
// the scrolling to occur
//
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
#end

This is the standard behaviour of UIScrollView which tableviews use. The system doesn't know that you want to scroll until you move your finger, but by that time you have already "pressed" on the button and so it assumes that's what you want to do.
You can play with a couple of properties on your tableview's scrollview to change the behaviour, but you may find they negatively impact the feel of your cells and buttons because of added delays.
self.tableView.delaysContentTouches = YES;
delaysContentTouches
If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent...
and
self.tableView.canCancelContentTouches = YES
canCancelContentTouches
If the value of this property is YES and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll.

Because all the above answers not working for me. I add a imageView on the button and make the imageView user interface YES, then add a tap gesture on the iamgeView. In the tap gesture related methods I put the button related methods in. so all is well..
may be hack. But it work well..

Below code works for me:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell = [tableView dequeueReusableCellWithIdentifier:#"cell_id"];
cell.userInteractionEnabled = YES;
if (cell == nil) {
cell = [[[CustomCell1 alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell_id"]autorelease];
}
[cell.button addTarget:self action:#selector(button_action) forControlEvents:UIControlEventTouchUpInside];}
-(void)button_action{NSLog(#"Hello!");}
This is my custom cell:
#import "CustomCell.h"
#implementation CustomCell
#synthesize button;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
button = [[UIButton alloc]init];
button =[UIColor redColor];
[self.contentView addSubview: button];
}
return self;}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame= CGRectMake(boundsX+50 ,+15, 100, 100);
button = frame;}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{ [super setSelected:selected animated:animated];
// Configure the view for the selected state
}

Related

UIbutton should not scroll with view [duplicate]

Basically, I wanna create a static UIButton on top whether or not the table view is scrolled. However, I tried to add the UIButton as the subview of the UIView and make it on the top by using "bringSubviewToFront" method. However, the UIButton still moves when I scroll the UITableView. Therefore, how can I make a static UIButton overlaying the UITableView?
Here is my code:
#import "DiscoverTimelineTableViewController.h"
#interface DiscoverTimelineTableViewController ()
#property (strong, nonatomic) UIView* myview;
#end
#implementation DiscoverTimelineTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self displayMakePlanButton];
NSLog(#"%f", self.view.layer.zPosition);
NSLog(#"%f", self.tableView.layer.zPosition);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = #"Sleepy";
return cell;
}
#pragma mark - Add the make plan button
- (void) displayMakePlanButton
{
CGFloat buttonWidth = self.view.frame.size.width;
CGFloat buttonHeight = 104.0f;
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
CGFloat statBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIButton *makePlanButton = [UIButton buttonWithType: UIButtonTypeCustom];
[makePlanButton setFrame:CGRectMake(0, self.view.frame.size.height - buttonHeight - navBarHeight - statBarHeight, buttonWidth, buttonHeight)];
[makePlanButton setBackgroundColor:[UIColor colorWithRed:0.286 green:0.678 blue:0.231 alpha:1]];
[makePlanButton setTitle:#"MAKE PLAN" forState:UIControlStateNormal];
[self.view addSubview:makePlanButton];
//makePlanButton.layer.zPosition = 1;
[self.view bringSubviewToFront:makePlanButton];
NSLog(#"%f", makePlanButton.layer.zPosition);
}
#end
You're using a table view controller, so self.view is the table view. A table view is a scroll view, so the view scrolls along with everything else.
You should use a regular view controller with a table as a subview instead.
Alternatively, you could try resetting the view's frame in the scrollViewDidScroll: scroll view delegate method, but I think the view would still jitter a bit.
Finally, you could add the button directly to the UIWindow, but that's likely to bring up a whole host of other problems with rotations, animations, and transitions.

UIView vs UITableCellView to show user posts

My app has a home screen where I show user posts loaded from the server. My problem is that I use UIView for each post, but it takes up a lot of space (also the user keeps on scrolling making it more memory consuming). Ex:
UIView* box=[[UIView alloc]initWithFrame:CGRectMake(0, postY, maxWidth, 500)];
[box setTag:(NSInteger)[post_id[i] integerValue]];
[box setBackgroundColor:[UIColor whiteColor]];
//Profile pic+++
UIImageView* profile_img=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
profile_img.layer.cornerRadius=profile_img.frame.size.width/2; //Make it round
profile_img.layer.masksToBounds=YES; //Make it round
profile_img.layer.borderWidth=0.5;
profile_img.layer.borderColor=[rgb(214, 222, 231) CGColor];
[box addSubview:profile_img];
And so on...
Does anyone know a better way of doing this? I tough of UITableCellView but it seems to be odd doing this task this way
I recommend you use a UITableViewController and then subclass UITableViewCell to create a custom cell for you to display the data. A UITableViewController instance contains a UITableView and you display the data by setting it in your custom UITableViewCell subclass. So basically, a UITableView contains various UITableViewCell and use the delegate methods to respond to events and actions on your table.
// YourCustomTableViewCell.h
#import <UIKit/UIKit.h>
#interface YourCustomTableViewCell : UITableViewCell
// Setup the properties for the cell, e.g
#property (strong, nonatomic) IBOutlet UIImageView *profileImageView; // Connect to outlet in storyboard file
#end
// YourCustomTableViewCell.m
#import "YourCustomTableViewCell.h"
#implementation YourCustomTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.profileImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
}
return self;
}
- (void)awakeFromNib
{
// Use this method to setup frames and sizes of your properties
self.profileImageView.layer.cornerRadius = profileImageView.frame.size.width/2; //Make it round
self.profileImageView.layer.masksToBounds = YES; //Make it round
self.profileImageView.layer.borderWidth=0.5;
self.profileImageView.layer.borderColor = [rgb(214, 222, 231) CGColor];
}
#end
// YourTableViewController.h
#import <UIKit/UIKit.h>
#interface YourTableViewController : UITableViewController
#end
// YourTableViewController.m
#import "YourTableViewController.h"
#import "YourCustomTableViewCell.h"
#interface YourTableViewController ()
#end
#implementation YourTableViewController
- (void)viewDidLoad
{
// Setup your data source for the table
self.tableView.dataSource = self;
// Setup other stuff after loading the view
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; // Return the number of sections you want in the table view
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows for each section, in your case this would be something like this
return self.posts.count; // If your data is stored in an array
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = #"YourCustomCell";
YourCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
if (!cell){
cell = [[YourCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
// Configure the cell...
// Here you add the code to display the data in the cell e.g.
[cell.profileImageView setImage:yourImageToDisplay];
return cell;
}
#end
As the comment said, you'd better choose UITableView as the posts' container and inherit from UITableViewCell as your box view.
Detailedly speaking much more, suppose the class inherited from UITableViewCell named MyTableViewCell, and you treat its contentView as your UIView *box. After that, you could tell the UITableView to use your MyTableViewCell as the Cell by sending him registerClass:forCellReuseIdentifier:.
Then, you can get MyTableViewCell instance by sending UITableView the
dequeueReusableCellWithIdentifier:forIndexPath: message. After being bound data (telling him display what posts), this instance can be returned to UITableView, which will arrange everything for you. Besides, these usually should be done in the UITableView's dataSource method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.

How to Put a static UIButton Overlaying a UITableView

Basically, I wanna create a static UIButton on top whether or not the table view is scrolled. However, I tried to add the UIButton as the subview of the UIView and make it on the top by using "bringSubviewToFront" method. However, the UIButton still moves when I scroll the UITableView. Therefore, how can I make a static UIButton overlaying the UITableView?
Here is my code:
#import "DiscoverTimelineTableViewController.h"
#interface DiscoverTimelineTableViewController ()
#property (strong, nonatomic) UIView* myview;
#end
#implementation DiscoverTimelineTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self displayMakePlanButton];
NSLog(#"%f", self.view.layer.zPosition);
NSLog(#"%f", self.tableView.layer.zPosition);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = #"Sleepy";
return cell;
}
#pragma mark - Add the make plan button
- (void) displayMakePlanButton
{
CGFloat buttonWidth = self.view.frame.size.width;
CGFloat buttonHeight = 104.0f;
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
CGFloat statBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
UIButton *makePlanButton = [UIButton buttonWithType: UIButtonTypeCustom];
[makePlanButton setFrame:CGRectMake(0, self.view.frame.size.height - buttonHeight - navBarHeight - statBarHeight, buttonWidth, buttonHeight)];
[makePlanButton setBackgroundColor:[UIColor colorWithRed:0.286 green:0.678 blue:0.231 alpha:1]];
[makePlanButton setTitle:#"MAKE PLAN" forState:UIControlStateNormal];
[self.view addSubview:makePlanButton];
//makePlanButton.layer.zPosition = 1;
[self.view bringSubviewToFront:makePlanButton];
NSLog(#"%f", makePlanButton.layer.zPosition);
}
#end
You're using a table view controller, so self.view is the table view. A table view is a scroll view, so the view scrolls along with everything else.
You should use a regular view controller with a table as a subview instead.
Alternatively, you could try resetting the view's frame in the scrollViewDidScroll: scroll view delegate method, but I think the view would still jitter a bit.
Finally, you could add the button directly to the UIWindow, but that's likely to bring up a whole host of other problems with rotations, animations, and transitions.

Reveal view when swiping a prototype table view cell

What I am trying to do is reveal a hidden menu when swiping on a UITableViewCell.
I have no idea how to do it, any guidance will be appreciated.
Here is an image so that you get an idea:
Image http://imageshack.com/a/img855/9134/j6k8.png
u can do it by using custom cell i give the ruff idea and sample code how to achieve this,
first create a new file objective-c, and name it as CustomCell subclass of UITableViewCell and in CustomCell.h file
i took some dummy views and labels
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell
{
}
#property (nonatomic, retain) UIView *optionsView; //this is your options to show when swiped
#property (nonatomic, retain) UIView *mainVIew; //this is your view by default present on top of options view
#property (nonatomic, retain) UILabel *messageLabel;
#property (nonatomic, retain) UILabel *optionsLabel;
#end
in CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//since we are not using the xib we hav to initilise hear
_optionsView = [[UIView alloc]init];
_mainVIew = [[UIView alloc]init];
_optionsView.backgroundColor = [UIColor greenColor];
_mainVIew.backgroundColor = [UIColor redColor];
_optionsView.alpha = 0.0f;
_mainVIew.alpha = 1.0f;
_messageLabel = [[UILabel alloc]init];
_optionsLabel = [[UILabel alloc] init];
[_optionsView addSubview:_optionsLabel]; //hear u can add image view or buttons to options view i just added the label
[_mainVIew addSubview:_messageLabel];
//add the gesture to main view
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(whenSwiped:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[_mainVIew addGestureRecognizer:swipeGesture];//add it to main view
UISwipeGestureRecognizer *swipeReverse = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(whenSwipedReversed:)];
swipeReverse.direction = UISwipeGestureRecognizerDirectionLeft;
[_optionsView addGestureRecognizer:swipeReverse]; //add it to options view so that user can swipe back
[self.contentView addSubview:_optionsView]; //first add the optionsVIew
[self.contentView addSubview:_mainVIew]; //then main view
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)layoutSubviews
{
[super layoutSubviews];
_optionsView.frame = self.bounds;
_mainVIew.frame = self.bounds;
_messageLabel.frame = _mainVIew.bounds;
_optionsLabel.frame = _optionsView.bounds;
_optionsView.alpha = 0.0f;
_mainVIew.alpha = 1.0f;
}
//handle swipe call backs in cell only and make a delegate to controller about the button actions of options view
- (void)whenSwiped:(id)sender
{
CGRect frameRect = _mainVIew.frame;
frameRect.origin.x = 300.0f;
[UIView animateWithDuration:0.5 animations:^{
_mainVIew.frame = frameRect;
_optionsView.alpha = 1.0f;
}];
}
- (void)whenSwipedReversed:(id)sender
{
CGRect frameRect = _mainVIew.frame;
frameRect.origin.x = 0.0f;
[UIView animateWithDuration:0.5 animations:^{
_mainVIew.frame = frameRect;
_optionsView.alpha = 0.0f;
}];
}
#end
in view controller import #import "CustomCell.h"
in datasource method of tableview
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *Cell = [tableView dequeueReusableCellWithIdentifier:#"CELL"];
if(Cell == nil)
{
Cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"CELL"];
}
Cell.selectionStyle = UITableViewCellSelectionStyleNone;
Cell.optionsLabel.text = #"options";
Cell.messageLabel.text = #"swipe me";
return Cell;
}
above is example, hope this helps u .. :)
and comment if don't get
Here is some guidance:
Each UITableViewCell could have two views, one on top of the other. The top-most view is what is shown by default, and the bottom-most view is what you call the "hidden menu."
You will need to register a UISwipeGestureRecognizer in your storyboard that manages the table cells you are showing above. You will create an IBAction for that gesture recognizer in your custom UITableViewCell class. In that action, you will handle the swipes that occur and then displace the top-most view of the cell by your desire amount, up to a maximum displacement (in the x-direction).
If you need more than this, let me know and I'll provide more info. I can't tell from your original question just how experienced you are, e.g., do you know how to create UITableViews with custom UITableViewCells?
UPDATE:
Make sure that you are creating a XIB file that houses your custom UITableViewCell. Then you can easily add the UISwipeGestureRecognizer to the XIB, and connect it to an IBAction in your cell class. In your UIViewController, you will register the XIB with a reuse identifier and populate your UITableView this way.

UIButton performance in UITableViewCell vs UIView

I'd like to add a UIButton to a custom UITableViewCell (programmatically). This is easy to do, but I'm finding that the "performance" of the button in the cell is slow - that is, when I touch the button, there is quite a bit of delay until the button visually goes into the highlighted state. The same type of button on a regular UIView is very responsive in comparison.
In order to isolate the problem, I've created two views - one is a simple UIView, the other is a UITableView with only one UITableViewCell. I've added buttons to both views (the UIView and the UITableViewCell), and the performance difference is quite striking.
I've searched the web and read the Apple docs but haven't really found the cause of the problem. My guess is that it somehow has to do with the responder chain, but I can't quite put my finger on it. I must be doing something wrong, and I'd appreciate any help. Thanks.
Demo code:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property UITableView* myTableView;
#property UIView* myView;
ViewController.m
#import "ViewController.h"
#import "CustomCell.h"
#implementation ViewController
#synthesize myTableView, myView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self initMyView];
[self initMyTableView];
}
return self;
}
- (void) initMyView {
UIView* newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] bounds].size.width,100)];
self.myView = newView;
// button on regularView
UIButton* myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton addTarget:self action:#selector(pressedMyButton) forControlEvents:UIControlEventTouchUpInside];
[myButton setTitle:#"I'm fast" forState:UIControlStateNormal];
[myButton setFrame:CGRectMake(20.0, 10.0, 160.0, 30.0)];
[[self myView] addSubview:myButton];
}
- (void) initMyTableView {
UITableView *newTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,100,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height-100) style:UITableViewStyleGrouped];
self.myTableView = newTableView;
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
}
-(void) pressedMyButton {
NSLog(#"pressedMyButton");
}
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:self.myView];
[[self view] addSubview:self.myTableView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:#"CustomCell"];
if (customCell == nil) {
customCell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"CustomCell"];
}
return customCell;
}
#end
CustomCell.h
#import <UIKit/UIKit.h>
#interface CustomCell : UITableViewCell
#property (retain, nonatomic) UIButton* cellButton;
#end
CustomCell.m
#import "CustomCell.h"
#implementation CustomCell
#synthesize cellButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// button within cell
cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cellButton addTarget:self action:#selector(pressedCellButton) forControlEvents:UIControlEventTouchUpInside];
[cellButton setTitle:#"I'm sluggish" forState:UIControlStateNormal];
[cellButton setFrame:CGRectMake(20.0, 10.0, 160.0, 30.0)];
[self addSubview:cellButton];
}
return self;
}
- (void) pressedCellButton {
NSLog(#"pressedCellButton");
}
#end
On the table view, under section "scroll view" there is the option "delays content touches"... remove it and the delay on button is gone but in this way table scroll don't start dragging the button.
I don't think it has anything to do with what you're doing (I tested it, and it is a little slow, but I wouldn't call it "sluggish"). It probably has to do with the various gesture recognizers attached to a table view -- the operating system has to figure out what gesture is happening, and that may cause a slight delay. This is the log of tableView.gestureRecognizers:
2012-10-09 20:34:12.355 SlowButtonsInTableView[3635:c07] (
"<UIScrollViewDelayedTouchesBeganGestureRecognizer: 0x71b42b0; state = Possible; delaysTouchesBegan = YES; view = <UITableView 0x789f800>; target= <(action=delayed:, target=<UITableView 0x789f800>)>>",
"<UIScrollViewPanGestureRecognizer: 0x71b4940; state = Possible; delaysTouchesEnded = NO; view = <UITableView 0x789f800>; target= <(action=handlePan:, target=<UITableView 0x789f800>)>>",
"<UISwipeGestureRecognizer: 0x71b4e00; state = Possible; view = <UITableView 0x789f800>; target= <(action=handleSwipe:, target=<UITableView 0x789f800>)>; direction = right,left>",
"<UIGobblerGestureRecognizer: 0x71b5100; state = Possible; enabled = NO; view = <UITableView 0x789f800>>"
)
With scrolling on table view not enabled the delay disappear completely, probably the delay is caused by the gesture necessary for scrolling

Resources