How to add view beside tableviewcell with Swift? - ios

I'd like to add view beside tableviewcell when user click table view cell.
before user click
---cell1---
---cell2---
after user clicked
---cell1---
---detailview---
---cell2---
How to do that?

If you are looking for something like another view appearing below the tapped cell and not an expanding tapped cell,you can insert a tableview cell just after the tapped cell.Use insertRowsAtIndexPaths and insert the cell.You can create this cell as a custom cell.

There is 2 options to do that:
- To make detailView as another cell, just insert below the cell user clicks
- Cell add the detailView initially. And make a switch to show it or hide it.Just because cell in table view is reused, we should not add subview in a cell already in table view, which will cause some problem in reusing.

Related

Preview a view in a table view cell from selecting a row on touch

In my table view cell I have a UIView that shows 5 stars rating. Users can tap it to change the rating. The problem is, when users change the rating the didSelectRow on the table view row is triggered. What is the best way of preventing this? Is there a way to block the UIView from passing the touch events to the table view? I still want the table view cell to be tappable outside the rating view.
1.If you are using buttons in ratting view for ratting?
if yes then increase button size
2.Otherwise you have to increase cell height for ratting view clickable.
I request you to provide screenshot of your tableview
and Answer if you are using any library for ratting.
You could override UIResponder's next property to break the responder chain:
extension CosmosView {
open override var next: UIResponder? {
return nil
}
}
See https://developer.apple.com/documentation/uikit/uiresponder/1621099-next.

How to keep subview on UITableViewCell

When the user taps the accessory view, the profile image in the UITableViewCell gets darkened by a black view that gets added on as a subview.
Here is what the cell looks like with the black subview:
Here's the issue: When I tap on another cell, the subview gets removed from the first cell and added to the second:
I would like to keep the subview for all cells that have been tapped.
Here is the code in which I handle that functionality:
self!.profileImageBlackView.cornerRadius = cell.followUserImage.frame.height/2
self!.profileImageBlackView.frame = cell.followUserImage.frame
cell.followUserImage.addSubview(self!.profileImageBlackView)
cell.followButton.hidden = false
For some reason, the follow button gets added to both cells, but the "profileImageBlackView" gets moved from cell to cell depending upon which one was activated.
You cannot display the same view in different cells. If you add the view to another cell it's removed from the first one. You must create a separate view for each cell.

How to hide the particulars uitableViewCell webview in when i click on that particuar cells button uitableview?

In tableviewcells i have a buttons and webViews, with some array count.so when i tap on particular tableViewcells button action. i have to hide that particular tables cells webview?
You can do it like this, In UIButton action, you will get cell index if you've given tag to your button, using that tag, you can make cell object with NSIndexPath for the cell you've tapped, hide UIWebView subviews within that cell, you may need to set its height base on some condition which you've made in heightForRowAtIndexPath of UITableView. Another way to get the cell is, [button superview]; here you'll get containerview for particular cell, and apply the same logic, this would only work if you've added button and webview in contentview.
[cell.webView setUserInteractionEnabled:NO];
Make the webView can't get the user touch focus, so that the cell will get the user interaction : )

Dynamically sized table in the cell of another table not resizing when reshowing view

I have a UITableView of cells where one cell contains a UITableView. Selecting that row that contains the table pushes a new view onto the screen with a list of items. The user selects a list of items and then presses 'back' to pop that view. The parent view looks at the number of items selected and the height of the cell is supposed to adjust to show all items selected.
What happens is that when the view is reshown, the listed items extends into the cell below. If I scroll that cell off the screen, then back to it, the cell is then the right height showing all items correctly.
I've tried several things such as putting code into viewWillAppear of the main table like [self.view setNeedsDisplay] and [self.view setNeedsLayout], but it doesn't work.
I can't seem to find a way to make that cell redraw to it's right size without scrolling the table once the view appears.
Is there some other method to force the redraw before it actually appears?
try:
NSIndexPath *theIndexPath = [NSIndexPath indexPathForRow:cellRow inSection:cellSection];
NSArray *theIndexPaths = [NSArray arrayWithObject:theIndexPath];
[table reloadRowsAtIndexPaths:theIndexPaths withRowAnimation:NO];
What are you currently using to redraw the cell? Just waiting for it to redraw itself when it goes off screen and back on? Or are you using something like [table reloadData];?

How do I respond to touching an empty UITableViewCell?

I'd like to launch my "add item" form in response to touching an empty cell (the next blank cell), sort of like the stock "Reminders" app. didSelectRowAtIndexPath doesn't work for this and I don't have a clue what does.
Thanks
add a button to the tableFooterView
https://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
You could add a tap gesture recognizer to the table view, but be sure to test if the user tapped a table view cell or not.
If you wanna the last cell of your table view to be an add button so that you can add a cell directly without putting the table view in edit mode, then here is what you can do:
For the array you use to populate the table view, always make sure the last cell is a dummy object you use to add a row only.
in your -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, make sure check whether indexPath.row is equal to [array count], if that's the same, then
insert whatever the object you create to your array at index = [array count]-1.
Call your [tableview reload] method. Then you will see the cell append to the table view.
Hope this helps.

Resources