Thursday, September 26, 2013

How in other ways in a UITableView cell on the Add button?

I would like to press the cell when the cell to the current long press to add a Modify button, seeking expert help!
UILongPressGestureRecognizer * btnEdit = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (handleLongPress :)];
btnEdit.minimumPressDuration = 1.0; / / seconds to set the response time
btnEdit.delegate = self;
[Self.tableView addGestureRecognizer: btnEdit]; / / Enable long press event
[BtnEdit release];

- (Void) handleLongPress: (UILongPressGestureRecognizer *) gestureRecognizer

{
CGPoint point = [gestureRecognizer locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: point] ;/ / get the response of indexpath
Pressif (indexPath == nil)
{
NSLog (@ "no data");
}
else
{
NSLog (@ "long press is:% d", indexPath.row);
/ / Add the modification method
/ / Cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImage * buttonUpImage = [UIImage imageNamed: @ "button_up.png"];
UIImage * buttonDownImage = [UIImage imageNamed: @ "button_down.png"];
UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom];
button.frame = CGRectMake (0.0, 0.0, buttonUpImage.size.width,
buttonUpImage.size.height);
[Button setBackgroundImage: buttonDownImage
forState: UIControlStateNormal];
[Button setBackgroundImage: buttonUpImage
forState: UIControlStateHighlighted];
[Button setTitle: @ "Modify" forState: UIControlStateNormal];
[Button addTarget: self action: @ selector (updateWebSite :)
forControlEvents: UIControlEventTouchUpInside];
/ / Cell.accessoryView = button;
}

}

Reply:
UITableViewCell * cellView = [tableView cellForRowAtIndexPath: indexPath];
[CellView addSubview: button];
Reply:
quote 1 floor ynb119 reply:
UITableViewCell * cellView = [tableView cellForRowAtIndexPath: indexPath];
[CellView addSubview: button];

Add a button for the cell
Reply:
In your code, you just created a UIButton, but did not add it to the cell up
After the completion of the creation:
[CellView addSubview: button]; can
Reply:
static NSString * UserListIdentifier = @ "UserListIdentifier";
UITableViewCell * cell = nil;
cell = [self.tableView cellForRowAtIndexPath: indexPath];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: UserListIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone; should I put this code together, thank you.

No comments:

Post a Comment