How to make the detailview and masterView communicate in the splitViewController? - iphone

I have a UISplitView with a masterView and a detailView. The masterView is a UITableViewController (inside a UINavigationControler) and the detailView is a UIViewController (also inside a UINavaigationController).
The UISplitView appears just fine with the masterView and an empty detailView. In masterView, I have this method:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (![self splitViewController])
DetailViewController*myDetailView = [[DetailViewController alloc] init];
Item *selectedItem = [items objectAtIndex:[indexPath row]];
[myDetailView setItem:selectedItem];
[[self navigationController] pushViewController:myDetailView animated:YES];
}
This works fine for iPhone.
For iPad, the detailView appears in the masterViewController, allbeit correctly, but the detailview remains empty.
How can I make myDetailview appear in the detailView (right side of the splitView)?

I recommend you to use Matt gemmell's MGSplitViewController
He has customized everything in the split view controller, you can get the master at right side using this and its just weird that you said that UISplitViewController is working fine in iPhone
To be clear UISplitViewController is specific for iPad and not for iPhone
So, please have a knowledge of iPad specific controllers like UIPopOverController and UISplitViewController
In Doc's, you can read this in the first line it self
Split view controllers are for use exclusively on iPad devices.
Attempting to create one on other devices results in an exception.

Related

Why my iOS tableview do not work

I am learning iOS programming and I had a problem with tableview.
By tapping a cell in tableview, I want my program change to another view,here is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
testViewController* controller=[[testViewController alloc] initWithNibName:#"testViewController" bundle:nil];
controller.imageView.image=[UIImage imageNamed:#"gyf.jpg"];
[self.navigationController pushViewController:controller animated:YES];
}
the view controlled by testViewController is super simple. There is only a image view in it.
But after I tap the cell, there was only a blank view on the screen without any image.
In debugging, after controller.imageView.image=[UIImage imageNamed:#"gyf.jpg"];,I found controller.imageview is nil.
Please tell me where is the problem and why this phenomenon happen,thank you very much
I use Xcode 4.3.3 and run the program on iPhone 5.1 simulator
(This answer assumes that your testViewController displays OK and is just not getting the image you want.)
When you create a new controller and push it, it's view hierarchy isn't loaded until it executes viewDidLoad:. You're trying to update its imageView before that happens. Try adding a UIImage property to testViewController, setting that property instead in this code, and then updating the imageView once all the views are valid in the new controller.

iPhone app, navigationcontroller not functioning?

I have 4 tabs in a tab bar. In one of the tabs i want to use a navigation, i.e. when i click an item from the list it should go to some details page about it. I have the list page where i have the navigation bar and the list of items. I can scroll them, but when I click any of them the selection animation happens, console logs the true row value, it even prints log instructions from constructor of the Details page but I can not see the Details page showing up. (btw Xcode 3.2.6 with iOS 4.3)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *rowValue = [myStrings objectAtIndex:indexPath.row];
NSLog(rowValue);
//[Utility setStr:rowValue];
[self.myTable deselectRowAtIndexPath:indexPath animated:TRUE];
//DETAILS PAGE HERE!!!!
RestViewController * rest= [[RestViewController alloc] init];
rest.scoreLabel.text = rowValue;
[self.navigationController pushViewController:rest animated:TRUE];
[rest release];
}
Anybody having any idea? Thanks in advance!!!
You can only use pushViewController: if your view controller stack is being managed by a UINavigationController. If the viewController you are trying to push onto is not being managed by a Navigation Controller, nothing will happen.
It sounds like this is the case if your app. Be sure your View Controller hierarchy is set up this way:
You have a UITabBarController at the top level.
The tab you are working with should manage a UINavigationController
Your tableViewController should be set as the rootViewController of the navigation controller in #2

How to call a detail view from a table view within a Storyboard

I have following problem.
I have created a tab based Application with three Views and Viewcontroller.
FirstView(Start screen stuff), SecondView (Detailpage), ThirdView (Table for listing items).
(Connections from storyboard were set automatically).
In the third view a table is integrated and the content is displayed fine.
Now I would like to call the SecondView , when a row in the table is selected.
I also tried to add a forth View , outside the tabBar Controller, to get the Detailview, but this also did not help.
I have tried several tutorials and forum tips, but cannot get it working.
The class is set to the right ViewController, the identifier is set to detail.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
detail.label1.text = #"It is working";
}
When clicking on the row, it becomes blue, but nothing happens. No error Message , nothing.
Hope that you can help :-)
OK, I have tried to "optimize" my design.
Still have the tab based Views, but when clicking on a row in the table, a new (not linked in Storyboard) view should appear to display the details of the selected quote.
I have created a view in the storyboard and called it "detailzitat"
I have created a DetailViewController.h/m as UIViewcontroller class
I have set the custom class to DetailViewController
I import the DetailViewController.h in the ThirdViewController.h
I have modified the didSelectRowAtIndexPath method in ThirdViewController.h accordingly.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"detailzitat"];
[self.navigationController pushViewController:detailVC animated:YES];
}
and my DetailViewController.m looks like
#import "DetailViewController.h"
#implementation DetailViewController
#synthesize label1, labeltext;
- (void)viewDidLoad
{
[super viewDidLoad];
labeltext=#"JUHU";
label1.text=labeltext;
}
But again, nothing happens, besides the row gets blue.
I do not understand. If I am using this code in a Non-Storyboard project, it is working.
What am I doing wrong ? Is there any tutorial for this combination within Storyboards ? Have not found one for this approach yet.
Try to learn from the different tutorials on the web, but the biggest problem is, most ones are not for iOS5 and I am not so good to transfer then.
Hope to get some hints :-)
You might want to think about your design. If I am understanding your description correctly, the user will be on the third tab, tap on a row in a table, and then you will be switching them back to the second tab. A navigation controller might be a more natural, less confusing, choice there.
But in any case, something like this will work sometimes:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.tabBarController.viewControllers objectAtIndex:1];
detailVC.label1.text = #"It is working"; // <- this will not work consistently!
self.tabBarController.selectedViewController = detailVC;
}
The problem with this is that while the user is on that third tab, it's possible that the second tab view controller's view is unloaded (due to memory pressure for example).
It's also possible the user went from tab 1 to tab 3 immediately and therefore the 2nd tab's view isn't even loaded yet at all. (To even test the above code you would have to select tab 2 and then tab 3.)
If the second tab's view hierarchy is not loaded, the label1 property will be nil, and so this will not work. A better strategy would be to create a new #property of type NSString* on the DetailViewController. And set that property instead of trying to set the label1 directly.
Then in your viewWillAppear: for the DetailViewController you can update your labels as needed. At that point of course you can be sure that label1 is loaded and connected to the correct UILabel.
I hope that helps.
I think problem is at self.navigationController. If your view is not inside the navigation controller this will not work. So what you do is create a new navigation controller object there and then use it to show your detail view.

Search Display Controller does not show searchBar

I created a simple TableViewController using the template offered by xCode.
Then I open the xib file of the TableViewController with Interface Builder and I drag/add a uisearchdisplaycontroller on the top part of the tableView.
xCode automatically creates and link all the outlets.
I save the xib file and I run the app but the searchBar is not displayed!
What else should I do to make appear the searchBar?!?
THANK YOU VERY MUCH!!!
I was having this exact issue. I would drag the search bar, it would "snap" into place on the table as a header, but it would never show.
I found that when you are presenting the next View you need to initWithNibName:
Example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewSubclass *dvc = [[UITableViewSubclass alloc] initWithNibName:#"UITableViewSubclass" bundle:nil];
[self.navigationController pushViewController:dvc animated:YES];
[dvc release];
}
This is also assuming you dragged the SearchDisplayController into the xib file. It will do all the necessary connections for you.
Hope that helps.

iPhone SDK: Pushed view controller does not appear

I want to add a detail view for one of the cells in my UITableView. I've created a new view controller SyncDetailViewController) and a NIB for the detail view. Didn't make many changes in the new class. Just added a label and outlet for it and connected nib with view controller.
Now I've added this code to my view controller (the one with UITableView, not the new one)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
SyncDetailViewController *dvController = [[SyncDetailViewController alloc]
initWithNibName:#"SyncDetailViewController" bundle:nil];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
The problem is that even if I select any row in the UITableView nothing happens. It doesn't produce any errors or warnings. I've added a breakpoint inside this method and it is reached so this code is executed.
Any ideas are much apprieciated.
"Nothing happens" sound so much like "sending a message to nil". Have you, by chance, checked that self.navigationController is not nil? Or that dvController is well initialized?