First, why: I have a class called AKTableViewController that inherits from UITableViewController and most of my View Controllers inherit from that.
I'm tryingto make a Category to add a banner on the bottom of each screen, not scrolling with the content, so I add my banner as the self.tableView.tableFooterView and than I position it on scrollViewDidScroll:.
My problem is, when the data is reloaded the banner is sent back to the right position and I don't have any callback to properly position it.
So: How to be notified when an UITableViewController has reloaded its data?
Use the delegate method for UITableView:
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
//Finished loading visible part of your table
}
}
The way you're doing this seems convoluted. It sounds like you should be adding the banner as a separate view, not as a footer of the table view.
Related
I'm using Objective-C. Here I have a tableview, and I set some actions using this method:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
So when I slide the cell, it looks like this: the cell
I want to dismiss these action buttons after I clicked on one of them. Which method should I use?
These code will do well:
[tableView setEditing:NO animated:YES];
I have a UITableViewCell that observes (via KVO) some properties. This only makes sense if the cell is visible. I want to remove this observer when the cell scrolls away, and before prepareForReuse is called.
How can I do this?
Your table view delegate can implement
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
and in there you can call a method on the cell to perform the cleanup you want.
Is it possible to remove indexpaths of UITableView that are off screen? My case calls for it, and I can't seem to find any methods or answers to remove an IndexPath.row that is off screen. I dont need to remove a cell, but only the indexPaths that are visible cells should remain.
Does this make sense?
Sorry I can't provide any code because I dont know where to start.
in iOS6, a new UITableViewDelegate function was introduced that does just this:
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
You can use this something like this:
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([tableView.indexPathsForVisibleRows indexOfObject:indexPath] == NSNotFound)
{
// This indeed is an indexPath no longer visible
// Do something to this non-visible cell...
}
}
If you are using UITableView properly and dequeueing cells using the method...
[tableView dequeueCellWithReuseIdentifier:#"blah" indexPath:indexPath];
then this will already be happening.
The tableview manages which cells are on screen. If you have 1000 rows in your table but only 10 rows on screen at a time then you will only ever have 10 cell objects in memory as those ten are reused for the rows that come onto the screen when others are scrolled off the screen.
I was wandering if its possible to have more than one uiTableView in one ViewController.
For example:
tableView1 and tableView2 in one view controller.
Initial start up of view controller, tableView2 should be disabled and not visible.
tableView1 should show the data associated with it.
When user selects a row from tableView1... it should then show the data corresponding to the selected row in tableView2.
tableView1 should still be enabled, and if user selects another row, the contents of tableView2 should also change respectively.
Thanks for any help or guidance given. :)
Of course you can do this. This is 5 minutes in storyboard.
You should choose UIViewController (not UITableViewController!)
And create something like this:
Then you should create object references with a ctrl key.
You have to remember that you have to set delegate and dataSource in both tableViews to your ViewController:
And in yout second table view set initialView to hidden.
Then in your code in method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath you should in first line call:
[self.mySecondTableView setHidden:NO]
and do all your stuff later. That's it.
EDIT:
Now i realize that you have set topic to "multiple" tableViews. This solution is messy enough for two TableViews. I suggest you to use container, and then all tableView will have own ViewController.
You can set different tags and outlets for this two TableView.
Then in
-(void)ViewDidLoad
self.yourSecondTableView.hidden = YES;
to hide second tableView
and when delegates methods was called
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
or
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
you can ask for tag like
if (tableView.tag == yourSecondTableViewTag)
return something
I have a main window which has two UITableViewControllers. On selecting the cell in first tableViewController (left pane), the tableViewContainer on the rightside gets populated. In the Voice over mode, I want that when the cell in the first tableViewController is selected, the first cell in the secondViewController gets focus so that the flick order starts from there. Please note that I have already tried the following two approaches:
1) Making the first cell of the second view controller, the firstResponder.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *outCell =(UITableCellView*) [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (indexPath.row == 0)
{
[outCell becomeFirstResponder];
}
}
2) I also tried posting the layout changed notification given the cell as the first accessibility item.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *outCell =(UITableCellView*) [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (indexPath.row == 0)
{
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, outCell);
}
}
None of the above approaches worked. Any idea what else can I try or what is wrong with the above approaches?
Please note that: I have read the View controller’s documentation (https://developer.apple.com/LIBRARY/IOS/#featuredarticles/ViewControllerPGforiPhoneOS/Accessibility/AccessibilityfromtheViewControllersPerspective.html - Moving the VoiceOver Cursor to a Specific Element). Tried posting LayoutChanged notifications as well as ScreenChangedNotifications in my sample as well as tried with the sample code (ListAdder - http://developer.apple.com/library/ios/#samplecode/ListAdder/Introduction/Intro.html, which also uses the NavigationController as we does), but the above did not work even with the sample.
Any idea why?
I solved this issue by posting the screen changed notification. The second parameter to that call is the table view's view that you want to select the first cell of.
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, [[self nextTableViewController] view];