Using a Custom Image for a Uitableviewcell's Accessoryview and Having It Respond to Uitableviewdelegate

Using a custom image for a UITableViewCell's accessoryView and having it respond to UITableViewDelegate

Sadly that method doesn't get called unless the internal button type provided when you use one of the predefined types is tapped. To use your own, you'll have to create your accessory as a button or other UIControl subclass (I'd recommend a button using -buttonWithType:UIButtonTypeCustom and setting the button's image, rather than using a UIImageView).

Here's some things I use in Outpost, which customizes enough of the standard widgets (just slightly, to match our teal colouring) that I wound up doing my own UITableViewController intermediary subclass to hold utility code for all other table views to use (they now subclass OPTableViewController).

Firstly, this function returns a new detail disclosure button using our custom graphic:

- (UIButton *) makeDetailDisclosureButton
{
UIButton * button = [UIButton outpostDetailDisclosureButton];

[button addTarget: self
action: @selector(accessoryButtonTapped:withEvent:)
forControlEvents: UIControlEventTouchUpInside];

return ( button );
}

The button will call this routine when it's done, which then feeds the standard UITableViewDelegate routine for accessory buttons:

- (void) accessoryButtonTapped: (UIControl *) button withEvent: (UIEvent *) event
{
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: [[[event touchesForView: button] anyObject] locationInView: self.tableView]];
if ( indexPath == nil )
return;

[self.tableView.delegate tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}

This function locates the row by getting the location in the table view of a touch from the event provided by the button and asking the table view for the index path of the row at that point.

How can I customize the accessory disclosure image in a UITableViewCell?

You'll need to create a custom view and assign it to the accessoryView property of the UITableViewCell object. Something like:

myCell.accessoryView = [[ UIImageView alloc ] 
initWithImage:[UIImage imageNamed:@"Something" ]];

Change image of accessory view of a table cell

Create a custom cell and create UIButton in the custom cell's and give the UIButton background image like "DetailButton"
May this help you.

Use UIStackView as UITableViewCell's accessoryView

You need to set “frame” constraints to your views

For example

stackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
stackView.topAnchor.constraint(equalTo: view.topAnchor),
stackView.leftAnchor.constraint(equalTo: view.leftAnchor),
stackView.rightAnchor.constraint(equalTo: view.rightAnchor),
stackView.heightAnchor.constraint(equalToConstant: 10l)
])

Or

stackview.frame = CGRect(x: 0, y: 0, width: 100, height: 100)

Follow this question

UIImage as accessory view in UITableViewCell not showing

The width of the UITableView was 804. Updating it to 768 allowed me to use the original code that was posted.



Related Topics



Leave a reply



Submit