I have an app with two bar in it.
one of the tab .xib includes UITableView, when the user select one of the cells, I want to show another UIViewcontroller (.xib file) that includes information about the his selection.
now, I've tried this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
NextViewController *nextController = [[NextViewController alloc] initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES]; [nextController changeProductText:[arryData objectAtIndex:indexPath.row]];
}
and nothing happened, the console is showing no errors at all.
what seems to be the problem?
thanks!
Nothing happened, because your self.navigationController returns nil.
For proper usage of Navigation controller, you must have at least one. For the case of TabBar application, for each tab you must associate not the UIViewController subclass, but UIViewController subclass nested in UINavigationController. That's easily done both in the .xib or in code. Just google for some tutorials.
Related
I am currently working on an IOS app to browse the folders on a remote computer and display the pictures. Now in order to browse the folders I am using the same table view and updating its cells, each time the user presses on a tile. Now after getting to the final list of contents(Images), I am trying to use a segue to navigate to UIViewController to display the Images. But I am getting an error: "segue not found".
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Fetch device
self->browseObjID = [avObjArray objectAtIndex:indexPath.row];
if([self->browseObjID isFolder])//To load same table view for browsing the folders
{
ContentL1TableViewController *targetViewController = [[[ContentL1TableViewController alloc] initWithMediaDevice:_devSelected andObjectId:self->browseObjID ];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
else
[self performSegueWithIdentifier:#"DisplayImage" sender:self];// display final image
}
You can only segue from a view controller that is created by a storyboard.
I'm assuming that you defined this TVC in a storyboard initially but that is only the first one.
When you are going to the subsequent TVCs you are creating these using alloc init and so they don't have a storyboard with a segue defined.
You should either create your image view controller using a xib file and load it from the xib or create it in code. Both would be easier.
Or you could define a "circular" segue that goes from the TVC back to itself and use this instead of creating one using alloc init all the time.
I have a UITableViewController within a UIViewController. While this table viewcontroller was the only one involved, it was pushing views just fine when the user would tap a row. However, ever since I moved it to be one of two contained within the UIViewController, the taps of rows suddenly do nothing.
I've tried searching around and I'm not the first to run into this problem, but none of the answers fit my circumstances or the questions have no working answers. That link was the closest I found, but I'm not using storyboards -- I'm using separate XIBs.
So how do I push a new view from a viewcontroller within a viewcontroller?
To recap:
Here is what I had, and it worked fine in taking users to a new screen!
// Normal table behavior, as illustrated by [another question][2].
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SomeView *detailViewController = [[SomeView alloc] initWithNibName:#"SomeView" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
Now I have the viewcontroller as a property in a view -- and the above code, which is in the file for the tableviewcontroller and not at the "main" view, doesn't cause a new screen to appear anymore!
Thanks for the comments! Here's some code to clarify my scenario.
The controllers within a controller. This is a file from a test project I've been using to test the concept out. In this case, I have a tableview controller within a tableview controller.
#interface SimpleTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
// This is the controller within the controller
#property IBOutlet SecondTableViewController *secondTableController;
#property IBOutlet UITableView *secondTable;
My SecondTableViewController has this fun bit.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:#"SimpleNonTableViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[manualViewControllerParent.navigationController pushViewController:detailViewController animated:YES];
}
The view that the user interacts with is hooked up to SimpleTableViewController. In this way, SecondTableViewController is "within" SimpleTableViewController. Feel free to comment if you'd like more details!
I've put my test/concept project on github. https://github.com/hyliandanny/TableViewCeption
You need to use a custom container controller to do what you want. It would be easiest if you used a storyboard, but you can do it in code with xibs as well. The outer controller should be a UIViewController, not a table view controller. You can do something like this (in the outer controller):
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:#"SimpleNonTableViewController" bundle:nil];
[self addChildViewController:detailViewController];
detailViewController.view.frame = set the frame to what you want;
[self.view addSubview:detailViewController.view];
[detailViewController didMoveToParentViewController:self];
}
You should read up on Apple's documentation for custom container controllers.
What you need to make sure:
Your UITableView delegate is hooked up to your controller. Otherwise it wouldn't call didSelectRow. You can do this in xib or in viewDidLoad method.
Your self.navigationController is not nil
Your detailViewController is not nil
I also think that what you mean is you have UITableView inside your UIViewController. UITableView is only the view, whereas UITableViewController is a controller. You can't have a controller inside another controller.
So I'm trying to push a UITableViewController from another controller and the search bar on my UITableViewController doesn't show up.
Here's my .m for the original table. (attempting to push to the "xSearch" view controller)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
xSearch *itemSearch = [[xSearch alloc] init];
}
if([[tableData objectAtIndex:indexPath.row]isEqual:#"Search"]){
[itemSearch setTitle:[tableData objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:itemSearch animated:YES];
}
In my storyboard, the "xSearch" viewcontrolelr consists of a table and a search bar. But only the table shows. Any help would be greatly appreciated.
By the way, I'm not trying to code the search bar. I'm just wondering why it doesn't appear when I run the app.
Because you are not initializing itemSearch using storyboard. You should initialize it using storyboard like-
NSString *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil]; //specify your storyboard name
xSearch *itemSearch = [storyBoard instantiateViewControllerWithIdentifier:#"xSearchStoryboardIdentifier"]; //You need to provide storyboard id in storyboard(Identity Inspector)
And then push it
[self.navigationController pushViewController:itemSearch animated:YES];
It might be due to re-sizing issue, navigation bar might be hiding the search bar.
Try hiding the navigation bar using:
setNavigationBarHidden:animated:
In your nib file change the view property to view with navigation controller.. Then design your XIB.. Study this link.
I am working on UISplitView Controller. I have used a SplitView controller template of Xcode. Actually i wanted to implement a scenraio in which when i click on table view cell it should add a New Root Controller with a table View into the Navigation Stack.
i did it using the following code
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NextViewController *nextView = [[NextViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:nextView animated:YES];
[nextView release];
}
It works perfect and i have used the RootView Controller code into the NextViewController so that when we click on New Screen's cell it should update my Detail Screen. But unfortuantely it is not updating my Detail Screen.
What can be the reason ??
Please help friends..
Thanks
To updating your Detail Screen. you need to implement a delegate method of communication between Current RootView controller and Detailview controller.
Best Wishes,
I have created a basic Split View and instead of loading a UIView on the right hand side, I have loaded a UITableView. The UITableView is made up of UITableViewCell's and what I want to do is when I click on the Cell, it loads up another UITableView for selection much like that in the iPad settings. However I cannot the UITableView to load after selection.
Any ideas how to achieve this? I've seen similiar questions and had a look at the apple site with uitableviews but haven't been able to solve the issue as they're geared towards iphone which doesn't have the split view.
On the didSelectRowAtIndexPath i've loaded it like so which other apps have done but to no avail.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0)
{
LevelTwoController *leveltwoController = [[LevelTwoController alloc] initWithNibName:#"LevelTwoTableView" bundle:nil];
[self.navigationController pushViewController:leveltwoController animated:YES];
[leveltwoController release];
}
}
Another thing also is my leveltwoController is a UITableViewController and I just keep getting this import error literal-pointer#_OBJC#_cls_refs.
Your main view that has the TableViewController needs to be controlled by a UINavigationController, and then you could push the subsequent views onto the view stack. My guess is your current implementation is having self.navigationController be nil so nothing is happening.
If you take a look at some of the basic xcode templates that use uinavigationcontroller's you should be able to figure out the proper path.