Im having major problems with Detail views and was hoping someone could point me in the right direction.
I would like to add a detail view to an app like apples advancetableviewcells. So once you click on a cell, it leads you to the detail view.
Only catch is, it has to load the data from the cell into the detail view also.
I've looked at allot of sites and allot of examples online, and I can see how it done with simple table but when it comes to individual cells and the data in the .plist. I'm lost.
Please any help would be great.
Thanks
Adding a detail controller isn't that difficult to implement. In your root view - I guess - you collect all the data from your plist file you mentioned above and order the data after your own criterias. Why don't you create a NSArray in the root view controller which contains a NSDictionary for every cell. In that dictionary you put all the information like title, price or something else of that object. In your detail controller just add an NSDictionary property.
If you select a cell, the didSelectRowAtIndexPath method is called. In this method you set the NSDictionary property in the detail view controller as the object in the NSArray of your root view controller at the index indexPath.row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *myDetailController = [[DetailViewController alloc] initWithNibName:#"NibBame" bundle:nil];
myDetailController.detailDict = [rootViewArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:myDetailController animated:YES];
[myDetailController release];
}
Afterwards all the data for the specific cell is now available in the detail view controller, and you can use the advantages of the NSDictionary and can get the variables just by a simple key. For example:
- (void)viewDidLoad {
self.title = [myDictionary valueForKey:#"specificKey"];
}
The table cell needs to be subclassed from UITableViewCell. You don't have to set the title of the view controller three or more times, it is always overwritten. You should set up your custom cell in the cellForRowAtIndex method and set the properties of the cell.
Related
I'm trying to make a very basic settings app where a user sets 5 options on a UIViewController and then performs a function based on the selected options. 3 of the options are in a container which contains a UITableView. When a cell from the table view is selected, a new view controller is shown with options for that cell (i.e. user selects "Metal" from the table, and then "Steel" from a new detail view controller). When a value is selected, the UIViewContoller/parent view is shown using an unwind segue and the detail text for the "Metal" row should display "Steel" in the container table
The cell selection segue works appropriately, and NSLog shows that the option selected is being stored correctly. The issue is that I can't figure out how to set the detail text label to the newly set variable. What code do I need to set detail text labels on the container table from the UIViewController?
A little additional info: my unwind segue goes back two view controllers. If I unwind to the table inside the container, the segue doesn't work on row selection.
Here's the prepareForSegue code from settings selection (the view controller that shows "Steel" from my example)
//Sets selected metal on row selection
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender: (UITableViewCell *)sender {
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:selectedIndexPath];
self.selectedMetal = cell.textlabel.text;
NSLog (#"%#", self.selectedMetal);
}
This is the code for my unwind segue and is executed once a detail row is selected:
-(IBAction) unwindToParentView:(UIStoryBoardSegue *)segue{
MetalTableViewController *child = (MetalTableViewController *) segue.sourceViewController;
//Trying to reference the container table here
OptionTableViewController *optionTable = [[OptionTableViewController alloc] initWithNibName:#"OptionTableViewController bundle:nil];
//Have a table view cell in the .h set as an IBOutlet that I'm trying to set here
optionTable.cell1.detailTextLabel.text = child.selectedMetal;
Update
The issue definitely has something to do with the new instance of OptionTableViewController that I'm creating. I can manually set the value of the the detailTextLabel for my container table view controller in its viewDidLoad method, but when I try to NSLog the value for optionTable.detailTextLabel.text it returns a (null) value which means I've got something wonky in my unwind block or I'm not passing the selectedMetal variable correctly.
To fix this issue, I changed my initial design a little and put all of my options in a table view controller. Now my segues work correctly and I'm not having any issues passing data between controllers. If anyone can propose a solution for the original issue (passing data from a parent view to it's embedded container view), I'll gladly give it a try and upvote the answer if it works.
I have 2 controllers.
I want to add a table view in the view controller,
and the table view's cell has the custom class of tableviewcell.
I tried to use [self addsubview:(the controller.view) into the controller.
I can see the list, but cannot set each cell's value.
In my viewcontroller:
TableViewController *viewController = [[TableViewController alloc] init];
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
I try to init the tableviewcontroller in my viewcontroller. Now i can see the tableview. But i cannot set the value of each cell. even more the break point cannot stop in the
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
You will also need to provide a delegate and a data source for your table view, and implement the required methods. I have a strong suspicion you skipped a couple crucial steps here. cellForRowAtIndexPath will never get called unless your view controller is properly set up as the UITableView's delegate and data source.
See the UITableView programming guide for more info.
I am facing a strange issue. I have a simple iPhone app with a TableViewController with custom TableViewCell that is parsing data using NSXmlParser and displaying it. The image inside the cell is loaded with SDWebImage library. Tapping on a cell will push the detail view controller which uses the link to show the post inside the UIWebView. Simple as that.
PROBLEM: When i tap on the cell and it shows the UIWebView, after that if i come back to the TableViewController, it stops scrolling. It bounces but doesn't go down where it has already loaded more cells.
I don't know where exactly the problem could be otherwise i would have added the code. Let me know if anybody wants some particular piece of code they want to see in order to find the problem. This is how i am pushing to the detail view:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *wvc = [self.storyboard instantiateViewControllerWithIdentifier:#"WebViewController"];
TheItem *entry = [[channel items] objectAtIndex:[indexPath row]];
wvc.urlString = entry.link;
[self.navigationController pushViewController:wvc animated:YES];
}
UPDATE: No matter even i select the last cell in the table view, when i come back from the detail view, the position of the scroll is at the top and stuck there.
Hi
anybody can explain of how to show a splitview when I tap a row from a cell??
or a tutorial of it??
I have a tableview, and i want to display information about that cell in a splitview.
Thanks
I don't think there's a tutorial for that, since you're not supposed to do that.
The split view controller is supposed to be the root view controller of your application, so if you want a pushable split view controller you'll have to write it yourself (or possibly find an open source one).
I want to implement an app that when it press a row from a table, it will open a splitviewcontroller that show the information
about the selected cell in the "detail´s splitview" , and all the info of the table in the "rootview".
I have copy to my project the
DetalviewController.h/m
RootViewController.h/m
DetailView.Xib
files from the splitview template.
And add this code to my tableviewcontroller:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Initialize the controller.
if(split == nil)
split = [[RootViewController alloc] initWithNibName:#"split" bundle:[NSBundle mainBundle]];
//Pass the current row number to the sub view controller.
split.number = indexPath.row;
//here is my problem, i cant add the new view, and it crash
[self.view addSubview:[split view]];
}
enter code here
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.