Push to same viewContoller - Objective C - ios

I have a tableViewController from that when I tap on a cell it should push to the same ViewController(for eg:sectionTableViewController -> sectionTableViewController(which will filter some data and show)). I tried to push to the same viewcontroller but I can't. Please help me out. Here is the sample code, i did the sample code in BlipFeedViewController.m
BlipFeedHash *feed = [[BlipFeedHash alloc] initWithHash:hashtag];
[self.navigationController pushViewController:[BlipFeedViewController viewControllerWithFeed:feed] animated:TRUE];
Thanks in Advance!!

Why don't you filter the data and then do [tableview reloadData] instead of creating a new ViewController.

Ann's answer is correct. While you could push to another view controller that conains filtered data, that's non-standard and takes more time than if the user could just filter on the same view. Do you have a specific reason why you want another view to display the filtered data? Have you considered the user filtering on the second viewcontroller, and then the third, creating a confusing chain of view controllers?
I beg you, please try to use a more standard filtering interface for the sake of all humanity.

Related

Pass data from detailed to master view? (UITableView) Swift

Sorry if the answer to this is obvious,
But I was wondering if anyone knew how to pass data from the detailed view to the master view of a UITableView system in swift using storyboards?
I have used prepareForSegue() to go from the master to the detailed view, but I don't think that that works when going from detailed to master. If it helps I'm working off the pre built "master-detail" template in Xcode.
Any help would be great appreciated. Thanks!!
There's a few approaches. It really depends what data you are trying to pass back. For example, if you're selecting a single item from a list, I'd define a delegate protocol for the detailViewController and have the master controller adopt it. Define a property for the delegate in detail, and set it in prepareForSegue:
destinationViewController.delegate = self
Then in the detail controller when the choice is made you just do [delegate didChooseObject:object] (Obj-C, sorry, I don't do Swift yet.)
Alternatively, if your detail controller is changing some value in a data structure, you probably want to have some sort of separated model object that both master & detail operate on. Pass the model object into detail in prepareForSegue. Use Key-Value Observing in master so that it knows what detail changed (if it cares).
A third option is to use a "completion block". Pass the block into detail, and have detail run the block with whatever data got picked.

What's the best way to load data for a ViewController before navigating to it?

In my application there are two view controllers that navigate to a DetailsViewController.
Right now, when the DetailsViewController appears, I fetch data from the server and display it on the UI. I dislike this because the UI is blank while the network request is going on. What I want is that the data be loaded in the previous view controllers and then passed to DetailsViewController.
Now the problem is that I have the exact same "load-data-and-then-push" code in two view controllers and I'm not sure what the most sensible way is to remove the repetition.
One idea is to have the two view controllers inherit from a common superclass which contains the loading/pushing method. I don't like this strategy because, supposing I have more ViewControllers like DetailsViewController down the line, I wouldn't like to write a loading superclass for each one.
Another idea would be to define a static method in the DetailsViewController which the two view controllers can invoke but this method contains UI related code (specifically, code to show an HUD Progressbar and a UIAlertView in case network fetch fails) which makes me uncomfortable.
I am very new to iOS and Objective-C so I might be missing something simple and obvious.
My favorite would be in this case to create a new class which handles the loading of the data (like http-request, etc.) and to create a delegate protocol for this class. This delegate callback might then be implemented in your two viewControllers which would then perform the push segue to your DetailsViewController when called. Delegation is a very nice and powerful feature, check out the documentation here: Delegation
Well, I'd better write it in the comments, but I have no reputation for that.
Imagine you are reading a json with several students information (name, year, etc.)
you can create a student object with the property that will be read and an object that will have a method that will run in the background that will be responsible for accessing your WS (JSON or whatever it is) and record this information to the student object. So if you have 10 students you will have an NSArray containing 10 students. This array is what you will for your next viewcontroller.
It is a lot of code, but you think examples easily.
If you use Storyboards you can use prepareForSegue: sender: to pass your data/model class to your DetailsViewController. If you use xib's you can do the same after instantiating the DetailsViewController and before pushing it.
If you need to load subsequent data from your server you should write a class that does this network stuff for you.
If DetailsViewController needs to load some additional data, you can use something like a loading view like Andy suggested. This is a widely used method.

Pass a string value to a cell on a different table view controller

I am new to Xcode, and I have been using examples I have found to try to make sense of it. I am trying to make an app that would take information from a QR Code and send that information to a table view.I would like to pass this value
[_qrCode performSelectorOnMainThread:#selector(setText:) withObject:[metadataObj stringValue] waitUntilDone:NO];
From a UIViewController (QRCodeViewController) to a Cell of a TableViewController (PatientTableViewController) that is using core data.
If you need more info let me know.
Thanks Again for any Help.
Is the QR Code Scanning controller presented modally on top of the Table View?
You'll probably want to insert a new NSManagedObject into your context from the scanning controller, and when the table view becomes visible again, you refresh your fetched results controller. This way the Core Data context remains consistent and the controllers don't need to be aware of each other.

How to get annotations on a map view while clicking a cell in a tableview?

I have a popoverview containing a tableview,showing some locations. Now my problem is, while clicking on the locations in the tableview i need to go to the view controller containing a mapview and get annotations . Unfortunately i don't know how to do it, i am new to Xcode. Please anyone help me.
The table view has to notify the view controller in charge of the map about the selection. The most common way to do this is with a #protocol and a delegate.
If you do not know how to do this, you should first learn how iOS works. I recommend the excellent and free Stanford University course.

Hierarchical master-detail app with xcode

I'm searching any tutorial or explication how to add a "level" in a table-view.
I'm using XCode 4.3.2. I've created a Master-Detail App, and I did all what I should for a working application. But I have only one Level in my table view, and have absolutely no idea how to get a second level.
I searched a lot in Google and in the Apple documentation, but I haven't found anything..
My wish is to have the list, when you click on an object of the list, you go to the second level with a new list, and when you click on an object of the second list, it changes the Detail View.
I think what you mean is going to the next view controller.
What you should do is use the delegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
(Link to doc)
Here you can create a new tableViewController, e.g.
UITableViewController *newTable = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:newTable animated:YES];
However, what you want to do (I guess) is send data to it which is should show. So, in your newTable tableviewcontroller you should create a new init method which allows you to send in the data you need. For instance an array. The class can then handle that data and show it as you please.
I hope that answered your question.

Resources