Linking two TableViews through a TabBar - ios

I've got 2 views, the AlllocationsViewController and the LoactionsViewController which are linked to each other.
That's how it looks in storyboard:
Each cell of the AlllocationsViewController links to the LocationsViewController and sends it some data to view in a tableView: AlllocationsViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
LocationsViewController *locationsViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"LocationsViewController"];
//Will send the data from the cell to the next view into 'locationlink', which is set as property in LocationsViewController.h to retrieve the data
locationsViewController.locationlink = cell.detailTextLabel.text;
[self.navigationController pushViewController:locationsViewController animated:YES];
}
Now I want to put a TabBar through those views:
After inserting data, If I leave the code below like that, the TableCell will send the user to the TableView (LocationsViewController), but without showing the TabBar.
What do I have to change in the code below so it shows me the TabBar too? Do I have to link to the TabBar instead of the locationsViewController now? Or do I have to set the TabBar in the LocationsViewController?
Any help appreciated.

Maybe this is a little late, but i think i can help you.
I prefer to use PrepareForSegue, but in your case you can use something like this...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
ClassTabBar *TabBarController = [self.storyboard instantiateViewControllerWithIdentifier:#"TabBarClientes"];
Locations *locationViewController = [TabBarController.viewControllers objectAtIndex:0]; // you can use the index you need
locationViewController.locationlink= cell.detailTextLabel.text;
[self.navigationController pushViewController:TabBarController animated:YES];
}
Tell me if I can help you in something else

Related

Opening new view from TableViewController

I have table view that holds an image and some text. The idea is to open a new view with the specific image and the text displayed when the user clicks the instance in the table view.
I am thinking about solving this simply by having a button overlaying the cell in the table view, but it feels like there should be a simpler built in solution, like a onCellClick(Any sender) function, but I havent found it. Some help please?
Yes there is a simple solution and that is to use the UITableViewDelegate method didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.textLabel.text;
UIImage *image = cell.imageView.image;
// here create a new view controller and send these details to your new view controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil]; //Main = your storyboard name
DisplayDataViewController *displayDataViewController = [storyboard instantiateViewControllerWithIdentifier:#"displayDataViewController"];
//set data in new view controller before pushing that on top of your navigation controller
displayDataViewController.imageName = image;
displayDataViewController.displayStr = cellText;
[self.navigationController pushViewController:displayDataViewController animated:NO];
}

Push a view when click the tableviewcell

I want to push a view when I click the cell of my tableview.The code is as followed:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == todoTableViewTag) {
NSLog(#"aa");
ViewControlleraaa* testvc = [[ViewControlleraaa alloc] initWithNibName:#"ViewControlleraaa" bundle:nil];
[self.navigationController pushViewController:testvc animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
but it does not work at all.
I have
ViewControlleraaa.h ViewControlleraaa.m and ViewControlleraaa.xib
but I did nothing except creating them.
So where is the problem?
Create a 'generic' segue from your table view controller to ViewControlleraaa and use 'performSegueWithIdentifier'. If that approach is not possible to execute then you may want to try 'presentViewController' instead.
Try creating a manual segue from your table view controller to ViewControlleraaa. Then, as the answerer above me said, you can use performSegueWithIdentifier to call the segue. If you should ever need the table view controller to push any data to the ViewControlleraaa, you can do so using the "prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender" method. The destinationViewController property of "segue" is ViewControlleraaa.
Here's a link to a YouTube video, in case you need any additional help: https://www.youtube.com/watch?v=XApYtAlRDVE
Check self.navigationController is not nil then surly it will work fine.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}

ios - naming and make action from each cell

So I'm using this code... "MFSideMenuDemoStoryboard"
https://github.com/mikefrederick/MFSideMenu/tree/master/Demos/MFSideMenuDemoStoryboard/MFSideMenuDemoStoryboard
And I want to give a name to each cell in the "SideMenuViewController.m" and make each one of these cells show a specific UIView in the "DemoViewController.m". any help with that ?
any help is appreciated, thank you!!
In SideMenuController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DemoViewController *demoController = [[DemoViewController alloc] initWithNibName:#"DemoViewController" bundle:nil];
demoController.title = [NSString stringWithFormat:#"Demo #%d-%d", indexPath.section, indexPath.row];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
NSArray *controllers = [NSArray arrayWithObject:demoController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
Replace this code with something like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//EDIT #1
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
DemoViewController *currentCenterView = [[navigationController viewControllers] firstObject];
[currentCenterView addAnotherView:indexPath.row]; //This is where you will tell your 'middle view' to load another UIView ... You can use the indexPath.row to determine which option was tapped and act accordingly.
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
You obviously need to add a method - (void) addAnotherView:(NSInteger ) row; to your DemoViewController or whatever you've called it.
Edit #1 this will reference the current loaded view. This will only work if you are only using 1 view controller on the navigation controller stack. Otherwise grabbing the first object won't work and you'll need to search for the right index.

Send data from master to detail view

Hi I am new to iOS programming and My requirement is to send the table cell text to detail view and display that text in detail view.
Master view
I have connected those view controller with segue. My master view controller is adding data in table view using below function.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [_types objectAtIndex:indexPath.row];
return cell;
}
After that I am assigning the text of current selected table view cell to 1 variable using below function.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_type = [_types objectAtIndex:indexPath.row];
}
And for passing the selected table view cell's data to detail view controller I used below function.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"CellSelection"])
{
CellSelectionViewController *controller = (CellSelectionViewController *)segue.destinationViewController;
controller.msg = _type;
}
}
Detail View
In detail view I am just alerting the passed data sent from master view.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test" message:_msg delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
Now my problem is
When I click on any cell, it loads the detail view but sending null value.
When I go back and again click on a cell, it sends the value which I selected previously.
Anybody knows what is the problem here?
It looks like you're using didSelectRowAtIndexPath and a segue. You should use one or the other. So, you could either:
You could retire your didSelectRowAtIndexPath method and then have a prepareForSegue that:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"CellSelection"])
{
CellSelectionViewController *controller = (CellSelectionViewController *)segue.destinationViewController;
controller.msg = [_types objectAtIndex:[self.tableView indexPathForSelectedRow].row];
}
}
Alternatively, you could remove the segue from the table view cell to the next scene, but rather define it to be between the two view controllers, give it an identifier, and then have didSelectRowAtIndexPath invoke it after your property was set:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_type = [_types objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"yoursegueidhere" sender:#"self];
}
But don't have both a segue from the cell and a didSelectRowAtIndexPath method. You have no assurances as to the order they will be performed. I'd be inclined to adopt the first approach and retire didSelectRowAtIndexPath altogether.

IOS - get a value from a table view controller and send it to another table view controller

I have two Table View Controller in a Navigation Controller. The Cloth table is the main view and when I click on one of the cells go to another view controller that gives me the detail, when I select the option i want and return to the Return of the Navigation button, I lose the information. How do I take the value to the main view?
Here my code: Main View - AddClothViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[list objectAtIndex:indexPath.row] isEqual:#"Categorias"] )
{
CategoriesViewController *DVC = [[CategoriesViewController alloc] initWithNibName:#"CategoriesViewController" bundle:nil];
[self.navigationController pushViewController:DVC animated:YES];
}
}
Here my code: Categories ViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set the checkmark accessory for the selected row.
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
// This is my main View Controller when i declare a variable category and I try to access from
//here
AddClothViewController *DVC = [[AddClothViewController alloc] initWithNibName:#"AddClothViewController" bundle:nil];
DVC.clothNew.categoria = [list objectAtIndex:indexPath.row ];
}
I resolved my problem by using this tutorial.
(Simple delegate tutorial for ios development)

Resources