Hierarchical master-detail app with xcode - ios

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.

Related

How can I give a particular behavior to a UITableViewRowAction?

I have a standard UITableView of items. Tapping a row will bring a DetailsViewController with details about the selected item and the possibility to use it through a UIButton.
I have implemented the (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath method made available from iOS 8 and I defined two actions:
The standard deletion of the item (pretty simple stuff).
The possibility to use the item like above. I basically want this action behavior to be the same of the IBAction related to the button in the DetailsViewController.
I thought about presenting this view controller automatically and making an automatic tapping of the button without using interaction, but this could be a bit confusing for the user according to me. So I would prefer to call the IBAction method directly from the table view controller. Is it possible and how can I achieve this result?
I can provide the source code if this could help you to help me.
What you need to do is take the "use this thing" action out of your ViewController, and put it in the Model object for "thing."
Then, when you want to use your "thing" from the tableView or the DetailsViewController, you can call this function directly on the associated model object, and allow your two (possibly more) different user interfaces to perform the "use that thing" functionality appropriately based on their own UI needs.

UITableView inside UIViewController not displaying

I am trying to set up a UITableView inside of a UIViewController. I'm doing this because it allows me to add a top bar with save and cancel buttons. I'm using storyboard and static cells to model the tableview to get input from the user (think of the create new event in Apple's calendar app). I have the view in Xcode, but when running it on my phone or the simulator, the tableview does not display. Here is the simple view in Xcode:
And this is how it displays when running it:
I've read about adding delegates and setting the datasource and such, but really this is all just going to be static cells with text fields, no data being loaded. Why is this happening and what can be done to fix it? Thanks!
#Made2k It looks like you found a solution, but for others who come across this with the same issue, note that you can only use a UITableView with static cells inside of a UITableViewController. This is not a well-documented fact, but apparently only UITableViewController knows how to handle the layout of static cells, whereas a regular UIViewController just needs to implement the UITableViewDelegate and UITableViewDataSource protocols in order to handle display of content in a UITableView added either programmatically or via Storyboard/Nib.
Hopefully this will save someone some time. #Made2k's solution is fine, but does make your storyboard unnecessarily busy. If you don't need to use a UIViewController, then just do your work inside a regular UITableViewController and save yourself a headache.
If you want to use a UITableView in a UIViewController you have to make the ViewController a data source and a delegate of the TableView and then implement methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
In case of a static table, in the cellForRowAtIndexPath you'd return outlets of the static cells. For a detailed description check out this answer:
https://stackoverflow.com/a/19110821/3110536
I ended up thinking about this in a different kind of way. The problem I thought I was having was I wanted all the features that a navigation controller provides, but I needed this to be the base of the controller, i.e. nothing to go back to. I was thinking that the only way to do this was to create a UIViewController and add the table view and such in there, but what I came up with is to simply just create a new navigation controller and now this view shows up as the root view like so:
I don't know if this is the best practice, but hopefully it can help somebody else if they are having this problem.
Man, following Hack really works!
You should give it a try!
In my requirement I wanted to add buttons in my Static cells too!and Toggle the visibility of the TableView
[self.tableView setHidden:YES/NO];
and Reload it with new data
[self.tableView reloadData];
and so many things is possible with that way of doing it!
https://stackoverflow.com/a/19110821/1752988
Hope the above link would help you! (Y)

Push to same viewContoller - Objective C

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.

ios/iphone sdk form management best practices

I'm working on an iPhone app that will have involve a lot of forms. Currently I have a ViewController class for each settings page which has an UITableView loaded with possible settings. When someone clicks on a setting they are taken taken to a new view to enter the form value, or allowed to enter things in place.
What's the best way to keep things DRY? What pieces of this implementation could be implemented once and re-used?
When someone clicks on a settings option which goes to a new view how can I create this view and add a text field according to the data type (uitextfield or picker or something else) in code?
You can programmatically:
create view hierarchy
UIButton
UILabel
You get the idea.
However, I would recommend getting your logic working for a few of the cases, and then it should become obvious what parts are redundant as you find yourself typing in the same thing over and over. At that point, refactor to get the redundant code into a re-usable form.
HTH.
If you have a tableView, the flow is to create the viewController of the selected settings in the didSelectCell method of your tableView delegate and to push it through the current viewController's navigation controller.
here's a sample:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController pushViewController:[self settingsViewControllerAtIndexPath:indexPath] animated:YES];
}
so you'll have to implement the method:
- (UIViewController*)settingsViewControllerAtIndexPath:(NSIndexPath *)indexPath;
wich will return the viewController managing the settings associated with the selected row of your root tableView.
If your forms are pretty statics, you should consider using a xib in order to minimize the amount of code needed. it isn't a perfect answer to your "how to keep DRY" but it's neat enough ;)
Good luck.

Appallingly dim UITableView question

I'm sure this is a very dumb question (or one that reveals terrifying levels of ignorance), but as an iOS newbie I'm trying to lash an app together as a favour to a friend - and any help would be greatly appreciated.
I have a multi-tab app, which is running fine. On the last tab, I'd like have a table view giving access to a variety of pdf or html files, to be stored in the bundle (and added to in future updates). Basically I want it so that if the user selects "Story pdf" in the table view, it loads up NextView with a UIWebView showing said pdf. If they select "Info table" then that UIWebView loads up info.html instead. It'll only ever be those two file types.
I've got the table view running and a new view ready and waiting, I just can't work out the next bit. Should I store names/file types in a plist? Is NSFileManager my friend here? If anyone has any pointers or knows of a sample project or chunk of code that does something similar, it would be fantastic.
Thanks for listening :-)
Your UITableView will have a delegate (possibly your view controller) and you need to implement this method from the UITableViewDelegate protocol:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you get the indexPath of the selected cell and then you work out what to do next.

Resources