Reputation: 6253
I have a UITablaView
in my Objective C application. I have the custom cells with a label and a UIImageView
. I want to disable a part of the rows, to disable didSelectRowAtIndexPath
when users click on this row's part.
I want this:
Is it possible?
Upvotes: 9
Views: 1920
Reputation: 1709
You may simply do change the image view width constraints to 0
. Where you want to action is performed. As for example:
1) If you use a button that cover the image.
2) If you take a navigation bar then you there take a button and perform the action.
hope this will help.
Upvotes: 0
Reputation: 1975
In my understanding the tricks with buttons and other UIElements that are covering the content are not the right way to solve the target. As you will need extra manipulations with them in Storyboard, if you will need to make dynamically content, if you will work with constraints and many more situations where you will need to control your content and + the artificial cover. There are few things to do:
UITableView
selection to No Selection
UIView
. This UIView will be the content container.Add UITapGestureRecognizer
to UIView
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectCellAction:)];
Add IBAction
where you could do all you need.
- (IBAction)selectCellAction:(id)sender
{
// do what you need
}
And thats all.
Upvotes: 0
Reputation: 601
Simply put the button over Green area and set tag for each button. Onclick you can perform your functionality using tag. Like this
inside
func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let obj: AnyObject = self.dataList.objectAtIndex(indexPath.row);
cell?.populateCellWithData(obj, indexPath: indexPath)
cell?.destinationLabel.userInteractionEnabled = true
let destRecognizer : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "DestLabelTapped:")
destRecognizer.numberOfTapsRequired = 1
destRecognizer.delegate = self
cell?.destinationLabel.addGestureRecognizer(destRecognizer)
}
and in DestLabelTapped you can peform your functionlity
Another way Just set two Tableview and scroll them side by side and one table is selectable and another is not. (don't do this)
Upvotes: 0
Reputation: 31645
You can do a simple trick (without the need of writing code) to solve this issue, by adding a button that covers the part that you want to disable the selection of it. Obviously, the button should not have any text or background color (it should be clear color), also make sure to add suitable constraints for making sure that is covered the wanted part of the cell.
So when tapping on the button, nothing should happen and didselectRow
should not get called because the actual touching event should be referred to the button, not to the row.
Hope this helped.
Upvotes: 1
Reputation: 167
This is very simple trick, Add a button on profile image part, means on red part as shown in picture (provided by you). And don't do on click on button click.
Happy Coding!!!!
Upvotes: 0
Reputation: 20379
Here is the simple and the most elegant solution that I can think off.
I believe you must be having a CustomCell, which holds the IBOutlet to imageView on the left side :) You can make use of hitTest
method to solve your problem :)
In your CustomCell lets assume it to be MyTestCell class write this,
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if self.myImageView.frame.contains(point) {
return nil
}
return super.hitTest(point, with: event)
}
Where myImageView is the IBOulet of imageView on the left hand side of your cell :)
All am doing is checking where did user tap, if the touch point is within the frame of cells imageView you return nil as the view. When you return nil touch event stops propagating to its parent views and finally will never reach cell hence didSelectRowAtIndexPath
never called,
On the other hand you should handover touch to the next view and you do it simply by calling same method on its super
iOS will eventually trace it back to cell and triggers didSelectRowAtIndexPath
Hope it helps :)
Upvotes: 12