I have a page with a button on it. When the button is pressed, i want the table view on the next page to add a cell with a label that has the text of 1 and i want there to be a picture also, but i know how to do this. I just want to add a cell to a table view when a button is pressed on the page before the table. How can i do this? Ive tried this code:
FinalCartViewController * viewController = (FinalCartViewController
*)self.parentViewController;
custom.customCellLabel.text = #"1";
[viewController addObject:[NSMutableDictionary dictionaryWithObject:
custom.customCellLabel.text forKey:#"name"]];
custom is an ivar that is created from the FinalCartViewController.
This code was in the method for the button that i want to use to add the cell. And i used [myTalbleView reloadData]; in the tableView's viewDidLoad. But my app crashes when i press the button to add the cell. Could somebody please help me? Thanks.
FinalCartViewController * viewController = (FinalCartViewController
*)self.parentViewController;
If the FinalCartViewController (I assume is the Table View) is the NEXT page, how can it be the PARENT view? The Parent view refers to the previous view.
You need to initialise the FinalCartViewController and save reference to it, so you can add objects to it. Although, the better practice would be to have a shared datasource that you add to and then pass to the FinalCartViewController.
Related
I have a custom UITableView integrated in my ViewController, with more elements, and I tried to add to the UITableView a control to refresh its content, like twitter app. The problem is that I can't capture the scrolls of the tableview in the ViewController. If I set the delegate of the custom UITableView, then I can capture the scrolls but I get troubles with the custom table behavior.
So, I don't know what it's better, either find the way to add the delegate for scrolls without override anything or find a way to add the control to refresh the table from the ViewController, not from the UITableView class.
The case with more details is:
A library for the custom UITableView. It's used to draw a conversation like the message app. So I just pass the information to the table and the table draw it. I don't do anything more, not delegate, nothing, just add the table to my ViewController.
I put the methods of the scroll's delegate in my ViewController, and, when I do scroll in the table, I don't get anything(the app doesn't enter in the scroll's delegate methods). If I set the table's delegate to self, the scroll works but I get some random problems from the table( I don't know how it's made the table), so I have to discard this option(set the delegate).
Thanks in advance
Try using the UIRefreshControl object. You define this object in the viewController in the viewDidLoad method and add the target to your tableView when it's value changes, here is an example:
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self.tableView action:#selector(reloadData) forControlEvents:UIControlEventValueChanged];
Your viewController needs to be a UITableViewController however. To initiate and end the refresh use the methods:
[self.refreshControl beginRefreshing];
[self.refreshControl endRefreshing];
I am trying to learn iPhone development as I've read many others on here are also saying. And Ive searched through about 20 pages of previous threads but couldn't quite find one that is what I need. I have a TableViewController as my root view that is inside a NavigationController. I have a grouped table with 2 cells inside the TableViewController and was wanting the text of which ever cell was selected to become the title of the next view's NavigationBar. I am using Xcode 4.3 and storyboards. Any help would be appreciated!!
In the tableview:didSelectRowAtIndexPath: method, I assume that you are creating and pushing your next view controller. You also must be having an Array (or some data source) which populates the text in the Tableview. So get the current cell's text by using indexpath.row. Set this text to:
nextViewController.title = cellText;
So when you push this view controller, it'll have the title of the cell selected.
try below it in didSelectRowAtIndexPath method will help you
detailViewController.title = [[[self tableView:tableView cellForRowAtIndexPath:indexPath] textLabel] text];
so i want to achieve something like this:
when clicking on this cell, there should pop a new tableview with the items availible, by clicking one of these items, it should go back and update the cell. normal stuff i think.
but i'm not shure how to do it the best way.
first i need to subclass a uitableview cell , because there is no default one for this, right?
and the rest?
should i set an ivar to the new popped tableviewcontroller with the selected cell and update the content after an item was selected? but then i had to reload table data , don't i ? wouldn't this break my selection, the scrolled way and all this stuff? would be a bit weird while the navigation-controller goes back to this tableview.
please help me with some best practices for this.
thanks and please leave a comment if something is unclear.
That cell style is UITableViewCellStyleValue1.
I would write a custom delegate protocol that the parent controller implements so that the child controller can inform it when the user has made the selection. But you can also use a property on the child controller. Or use a notification.
To update the cell in the parent view controller, just call [tableView reloadRowsAtIndexPaths:withRowAnimation:]. No need to reload the entire table.
I have a two tabbed application. The first tab is a NavigationController that has a few TableViewControllers in it. The second tab is also a NavigationController that has a TableViewController in it.
What I'm trying to achieve is: When someone clicks on a button in the TableView inside first tab, I want to add the the clicked row to the TableView inside the second bar.
I'm already saving the information when it is clicked to NSUserDefaults. When I quit the app and restart, the second bar shows the updated info. But it doesn't show the updated rows if I switch to it while the application is running.
How can I make the second bar reload/update dynamically with the updated rows when someone does sth in the first bar?
I've called [self.navigationController parentViewController] successfully to get the tabBarViewController, which is the highest level, when the the tableview in the first bar changes. How can I get to the TableView inside the NavigatinController inside the second tab from there to have it update itself? Or should I be doing this another way?
Thanks.
i think you can call reloadData in second bar's view controller function
-(void) viewWillAppear:(BOOL)animated
{
[tableView reloadData];
}
You could call the reloadData method on the UITableView within that TableViewController. Honestly, I think you should be using CoreData but I don't know enough of the structure of your data so... try that?
I did a simple view based application.
what i did is creating view additional to existing view.
means there is one view named main in .xib file additional to that i am creating another view
IBOutlet UIView *view_additional;
In the main view by button click i call the view_additional view.
For the view_additional view i place navigation bar with one bar button named back.
In the back button click event i need to get back to main view.
for that in the button click action i write the fallowing code.
[view_additional removeFromSuperview];
But it is not open main view,shows a white screen.
what the wrong.
how can i get back from additional view to main view.
Thank u in advance.
for the code you used to display view_additional, instead of using self.view = view_additional
try using, on button click
[self addSubview: view_additional];
And once that's done, your code should work just fine the way you want.
When dealing with views, if you change a view, then remove it, as you did in your code, then all that will be left is the main app window. There will be no views on that window. From the look of it, you want to load up a new view, and then remove it once you're done with it. You can do this by adding the new view as a subview instead of totally changing the parent view. Another thing you can do is set an IBOutlet for the original view as well, this way you'll have an outlet for both views, and then instead of removing your additional_view from the superview, you can just switch it back. So the code for the Back Button would just be
self.view = original_view;
on back button click. I hope this isn't too confusing for you. Let me know if you have any questions.
Both methods would work for what you want to do.
I resolve my problem as
instead of [self.view = view_additional];
i use
[self addSubview: view_additional];
To get back to original view in the button click
i use
[view_additional removeFromSuperview];
MahesBabu, that is exactly What I suggested that you do. Only I offered the background info on why you should do it that way.
# MaheshBabu:
This is the common code u can use to go on next view or go on back, Just change button name which u want to press and the view name on which u want to go. For example on back button press u want to go on library view then write this code -
-(IBAction)backButtonPressed:(id) sender
{
libraryView *libraryview=[[libraryView alloc] initWithNibName:nil bundle:nil];
libraryview.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:libraryview animated:YES];
[libraryview release];
}
Let me know whether ur problem is solved or not.