I am saving the indexPath selection from a subview and passing it to the parent view with delegates. When I got back to my subview from my main view I pass the indexPath back to it and show the user which cell they previously selected with a tick in the accessory view of the tableviewcell.
One problem being if the user has selected a cell out of a fairly big list its hard to find the cell they selected again incase they wanted to change it (being that they made a mistake)
I would like to know if their is a way to use indexPath or something similar to center the previously selected cell of the uitableview to the center of the screen?
UPDATE::
Here is a graphical view of what I am trying to achive to make it abit more understandable..
step one : select cell then go to subview and select the cell (value) you want to pass back to main view (save indexPath of selected cell)
step two: user either wants to change his selection or made a mistake and was ment to select the cell below the one they chose... repeat previous steps but display previously selected cell in the center of the view..
Have you tried the following function
[tableView scrollToRowAtIndexPath: atScrollPosition:UITableViewScrollPositionMiddle animated:YES]
a UITableView is a subclass of UIScrollView - try setting the Content Offset (figure out how much with the cell height and indexPath).
[tableView setContentOffset:CGPointMake(0, indexPath.row*cellHeight) animated:YES];
should work. You might want to do the math a little differently.
Related
I need a way of setting the UITableViewCellAccessory for any row. However the catch is that I need to be able to do it OUTSIDE of the UITableView delegate methods.
I have tried this, but it doesn't show up the accessory.
[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:1]] setAccessoryType:UITableViewCellAccessoryCheckmark];
If it makes any difference I created the UITableView in IB in a storyboard. The data is static, and I'm using a grouped table style with only one section.
Please can someone help me out?
If your table view is scrolled so the cell in question may sometimes scroll out of view and then back into view, you should manage the content of that cell only from within the UITableView method cellForRowAtIndexPath:. The reason is that when cells are redrawn, the tableview object calls this method to make sure that visible cells are properly rendered. (Cell that are not visible don't need to be rendered at all.)
That being said, this is where you should handle the cell content, even if the table view doesn't scroll the cell in question out of view. It wil lmake you life a lot easier if you follow this design pattern when working with table views.
Inside that method, you can test (using if statement, for example) the value of the indexPath.section and indexPath.row so that you can configure the specific cell the way you want it. This includes putting in the accessory.
Always use [NSIndexPath indexPathForRow:inSection:] when working with table views.
You can figure out what indexPath you need the checkmark on and then use something like this
UITableViewCell * cell = [tableView cellForRowAtIndexPath:someIndexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
I am working on a app where I want to expand a tableviewcell to cover almost all the screen with animation when it is selected by user. I am looking to create a uiview on the tableviewcell and expend it to cover major portion of the screen when user selects the row.
The main problem I am having is to get the frame from where my pop up view will start expending. How will I get the frame of the row which is touched?
Thanks
Pankaj
Is it crucial that the cell should not reposition?
If not ( i am guessing not, as you are anyway planning to cover whole screen):
When the cell is selected, scroll the cell to top (using scrollToRowAtIndexPath) and either insert your custom view to cell's contentView or modify its parameters if its already there with different opacity/size etc
Use UITableView function to get the rect for the row by passing the its NSIndexPath.
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath
How to get the selection cell still in the selected state in uitableview. Actually I am pushing a view from a tableview when came back then the selection cell is deseleted. I want to be show the previous selection cell when came back also how to do that.
In didselectrowatindexpath use the method selectRowAtIndexPath:animated:scrollPosition: and the row stays selected.
when you are going and coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.In cellforindexpath write the code of selection style uitableviewcellselectionstyleblue.
first, you can store the selected indexPath in user default in the didSelectRowAtIndexPath method.(maybe you can store a indexPath that is bigger than your table view's row count to indicate initialization stage, which means that no row has ever been selected)
then, you can load the stored indexPath in the viewDidLoad method using
tableView selectRowAtIndexPath:<#(NSIndexPath *)#> animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>
meanwhile, you can do some check (like mentioned above or something else) to check if there's nothing selected yet.(saving a bool in user defaults works, too)
I have a UITableView with some cells in it that have people's names. When the user clicks on a cell, the Navigation Controller pushes a new view onto the stack that shows detailed info for that person. When the user is done and clicks the button to return to the previous view, the tableview is again shown. The problem is that I want to edit the cell text (or just mark the cell in some way) to show that the user has clicked on that cell. In my cellForRowAtIndexPath: method I have set up code that should change the text of the cell after a user clicks on that cell. I set up break points and it IS entering cellForRowAtIndexPath: when the detail view is popped and the tableview is again shown. It's entering the segment of code in cellForRowAtIndexPath: that should change the text, but when it comes up on screen, the text has not been changed. Does anyone have any ideas as to what is going on? Thanks.
EDIT: I figured it out. I just needed to call [tableView reloadData]; instead of calling the cellForRowAtIndexPath method. Not sure why that works differently, but it fixed it.
I guess I'll help you out. You don't need to credit me with the answer though.
cellForRowAtIndexPath:
that method is called within the framework when a cell is being refreshed from the queue or when it needs to be created. You should not call this method.
[tableView reloadData];
that method is basically a refresh on all of the visible cells show in the UITableView. This is the method you should call if you change information in your data source or you need to (force) update the appearance of your cells.
It's Good You Have Reload Table And Changed The Text But If YouJustIndicate NAd Don't Want To Change The Text The nYou Can Use elow Given Text ....
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
It Will Check Mark Particuler Cell Which You Click/Visited......
Hope You Like This Solution.....
This is driving me nuts.
I have a TableView with custom cells. My cell contains a editble textview. Is it possible to change rowheight on cell and textview dynamicly (when I editing the textView) ?
best regards
You can't change the height of a tableview cell without reloading the table. This means that every time a new line is needed in the textview, the tableview needs to reload.
While this can be done (with much manual tweaking,) I don't think the results will make for a good interface. Instead, you should have the cell open a detail view and let the user type there. This is how all the Apple apps handle the same problem and it is the solution most users will expect.
It will also save you a heck of a lot time and frustration.
The row height is calculated from either the delegate or the table view's property. I think the height is determined when the cell comes into view.
One possible avenue is to use - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation.
Is the cell with with the text view unique in the table? You may run into problems if the user is in the middle of editing and the cell needs to be re-layed out and the text view is not unique.
yup!
try resizing your cell and calling
[tableView beginUpdates];
[tableView endUpdates];
every time you need to resize your cell.
that will call heightForRowAtIndexPath: and resize all your cells accordingly
so you want to return the proper height there..
hope that helps:)