UIPopoverController hierarchy/inheritance with other ViewControllers - iphone

I have a BaseController and three subclass ViewControllers. In each of the subclass ViewControllers, a query is made to the sqlite database to get the information. I want to add a longPress feature at the BaseController level to pop up a UIPopoverController.
So then I have a subclass of UITableViewController to be used with the UIPopoverController to display the data. Do I need to get the information from the sqlite database in my subclass of UITableViewController to have that information be displayed in UIPopoverController? It seems redundant since my 3 subclasses of the BaseController already have the data, and now I just want to have that data in a UIPopoverController, as well as add additional functionality like when a row is selected from the UIPopovercontroller.

The UIPopoverController is a view controller.
SO:
display the table.view in the UIPopoverController.
As far as adding functionality to a row press:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// in here write what happens. if its row specific write:
/// if (indexPath.row == ROWNUMBER){method} (rows start at 0)
}
and all of this goes in the .m file of the tableView you are presenting

Related

UITableViewController freezes when segue to another UITableViewController

I have a TableViewController (VC1) set to push-segue to another TableViewController (VC2). This connection was made in storyboard via ctrl-drag from VC1 to VC2. When the segue is performed, the app freezes and I see the CPU peg to 100% and memory usage start climbing rapidly. I started out with a custom VC2 and saw that viewWillAppear was called and the table delegate methods such as numberOfRowsInSection were being executed properly.
In an attempt to narrow down the problem I can see that even a vanilla UITableViewController (no custom controller class) as VC2 has the same problem. But when I set VC2 as just a vanilla UIViewController (not table), it segues fine.
I have about a dozen other TableView -> TableView segues elsewhere in my app that are set up the same way and no problems with them.
VC1 code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"myseguename" sender:self];
}
It turns out my problem was caused by trying to use appearance proxy to set the backgroundView of UITableView. Found in the docs (https://developer.apple.com/library/ios/documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html) that UITableView backgroundView is not marked as UI_APPEARANCE_SELECTOR.

UITableViewCell segue created in Interface Builder will not fire

Currently, I have a basic UI set up in Interface Builder that features a UITableViewController, with a seque leading from the prototype cell to a detail view. My code dequeues the cell with the identifier I have set in Interface Builder, but when testing the app, a tap on the cell does nothing but turn it blue.
I want the segue to push the detail view on to my navigation controller's stack, but the segue simply won't happen. Why could this be?
Assuming you are working on storyboards (segues, etc.) there is a bug in the auto layout scheme of iOS. Hence the segue is not fired. However, you can simply give the segue and identifier in attributes inspector of the segue, and programmatically from your class you can use
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
in this method you can fire the segue in the following manner.
[self performSegueWithIdentifier:(NSString*) target:(id)];
Let me know if this helps you.
(Make sure your delegates and datasources are all set up correctly).

TableView delegate method called only after a second cell is selected

I'm dealing with a problem that is really making me crazy. I've got a table view added to a view using IB. This tableView has a delegate and a datasource. The delegate is the view controller, the data source is another class that packs information for displaying them. The data source works and fill the table with correct data.
I'm not able to say the same for the delegate. The delegate implements the classic - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath and I have an NSLog inside that method that logs the cell selected.
The problem is that if I selected a cell, the cell changes its color in blue(selected state), but it doesn't trigger the delegate methods. If I press another cell now the new selection on a new cell pushes the detailviewcontroller with the right informations.
If I pop the cell is deseleted- since in viewWillAppear I put a method for deselect selected cell-, if I press a cell again nothing happens just blue selection,if I press another one it pushes the detail view.
I tried to make few changes to make the case easy as possible:
.used default styled cells
.added the tableview programmatically
.check the delegate of the tableview in different part of the code
Everything seems right I really can't understand.
Use
(void)tableView:(UITableView *)tableView selectRowAtIndexPath:(NSIndexPath *)indexPath
instead of
(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

Iphone -- push a view controller onto the navigation stack when a button is clicked in a UITableViewCell

When a button is pushed in one of my app's table view cells, I need to push a certain view controller onto the navigation stack.
This could be done by using an instance of NSNotification to inform the table view's controller of the button press. But that would be awfully heavyweight, especially since selections in a tab bar in the app could cause the table view to appear or disappear, creating additional overhead as the various table views register and unregister themselves whenever they are tabbed onto or off of the screen.
Can anyone think of a better solution?
Why not put
[[self navigationController] pushViewController:targetViewController animated:YES];
in the method called by the button?
Make your UITableViewController use the UITableViewDelegate Protocol and implement this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
From the indexPath you can get which row has been pressed and then you know which cell is being selected. The purpose of the UITableViewController is to know about the cells and the cell itself does not need a button to trigger an event to push a new view.
What I did was set the table view's delegate to be the same as its controller. Then:
UITableView *myTableView = (UITableView *)self.superview;
NSIndexPath *indexPath = [myTableView indexPathForCell: self];
MyTableViewController *myTableViewController = (MyTableViewController *)(myTableView.delegate);
[myTableViewController buttonWasPressedOnCellWithIndexPath: indexPath];

How can I call the parent TableView to reload

In this iphone app I'm trying to make it so that when you select a table cell it saves that action, pops the current view controller and calls the previous view controller (which is and always will be a TableView) to reload it's cells with new data.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//update data code here
[self.navigationController popViewControllerAnimated:TRUE];
//Here is where I want the code to reload the view [parentTableView reload]; or something }
That's what I have at the moment when you select a cell in the current Table View
You need need to send -reloadData to the UITableView:
[tableView reloadData];
Edit : So just to clarify, you have a parent UITableViewController which pushes a child UITableViewController onto the navigationController? The code in your sample is implemented in the didSelectRowAtIndexPath in the child view controller?
If this is the case, you need to to add a property to your child UITableViewController which stores a pointer to its parent. Make sure this isn't a reference counted property because that will result in a circular reference. So before you pop your child UITableViewController it can send -reloadData to the tableView property of its parent.