I'm trying to develop a basic GPA Calculator. I have an AllCourses class that holds Course objects.
I have an AllCourses object in my CalcAppDelegate.
In my ThirdViewController I can successfully update the number of Courses in my AllCourses object. However, the problem I'm having is that when I switch to the RootViewController the UITable isn't being repopulated with the updated Courses that were added.
I tried [self reloadData] in the viewWillAppear in my RootViewController but it caused my app to close. I didn't use IB to create the views so I think it could be the case that I don't have things hooked up correctly. I did it programatically. Does anyone see anything I'm missing in my code?
Here is the link to my project http://files.me.com/aahrens/q0odzi
Try
[[self tableView] reloadData]
The method is implemented in UITableView rather than in UITableViewController, which is why your app crashed.
have you tried [self.tableView reloadData]
Related
This is really frustrating as I've tinkered with previous versions of Xcode and have done this before but playing around with a new app now, it's not working for some reason.
I have the app open to a UITableView and want it to load to a detail UIView once I select a cell. However, when I choose a cell in the iPhone simulator, it just highlights the cell blue and doesn't load the view.
Here is the code I'm using the the RootViewController:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WorkoutViewController *workoutViewController;
workoutViewController = [[WorkoutViewController alloc] initWithNibName:#"WorkoutViewController" bundle:nil];
workoutViewController.workoutName = [workouts objectAtIndex:indexPath.row];
[self.navigationController pushViewController:workoutViewController animated:YES];
[workoutViewController release];
workoutViewController = nil;
I have the view linked to the File Owner in the WorkoutViewController.xib file. When I put in a breakpoint at #implementation WorkoutViewController, it does get to that breakpoint but it goes to the #synthesize line and then jumps right back out to [self.navigationController ...etc]; and never returns back to the WorkoutViewController.m file.
I would guess that you didn't set the ViewController to be the TableView's delegate. To check, open your ViewController xib-file and rightclick FilesOwner. Under Referencing Outlet you would usually have both delegate and data source" connected to your TableView. If that is not the case, drag New Referencing Outlet to your TableView.
If I'm wrong and they are all connected, you might want put a breakpoint at the beginning of your didSelectRowAtIndexPath method. Does the debugger stop there, once you select a row?
It might also be worth mentioning that a breakpoint at #implementation usually doesn't make much sense, you would rather want to place it in a method like init. Also, even though you are using Xcode 4 now, this is unlikely to be the cause of your problem, it looks more like an implementation issue.
Hope this helps, if you need further help just let me know!
Doh! Problem resolved. I had forgotten to actually put the RootViewController into a navigation controller on the MainWindow.xib. Appreciate the responses.
I have a table view set up in IB. It's delegate/datasource are connected to this class:
#interface EditPlayersViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
I'm trying to call the reloadData method. If I use [self.view reloadData]; it doesn't respond, I guess because technically self.view isn't a UITableView. I tried to add the following:
IBOutlet UITableView *myTableView
and then I connected it to my table view in IB. Now my program crashes when the view loads. Any ideas?
Make EditPlayersViewController a subclass of UITableViewController rather than UIViewController. Dump the explicit interface implementations and the IBOutlet. Then, [self.tableView reloadData] should work.
Watch the console when it crashes and then bring up the debugger window. Both of these windows will give you great insight into what is happening. The data you're trying to load may be to culprit and not the reloadData call.
Make sure you have implemented the UITableView data source methods.
put break points in data source methods and try to find out where it is crashing.
UITableViewDataSource_Protocol/Reference
I have a viewcontroller which contains a tableview. I call another view via pushViewController. When I get back to my original viewController I hope to redraw the table, but viewWillAppear is never called.
Any other ideas?
I've used this in my own projects with success.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self tableView] reloadData];
}
Double check the spelling of the method.
I had two classes competing for messages, UITabbarcontroller and UINavigationController. I had a UITabBar from a previous experiment. It was created but not used. The messages where getting to UITabBarController, and UINavigationController was never told.
Hope this solution will help someome someday
I'm having the following issue:
I have a tab-style app. Eacht tab has its own viewcontroller and xip. Within the first tab-view, I try to display a button which load a next view, showing a grouped tableView. Everything works as expected, the numberofSectionsInTableView is called, and then I get an ext_bad_access error.
I try to explain my setup:
First (by the click of a button), I load the nip of the view:
FiltersViewController *filtersViewController = [[FiltersViewController alloc] initWithNibName:#"Filters" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:filtersViewController animated:YES];
[filtersViewController release];
In the NIB, the File's-Owner is set to the FiltersViewController class. The view-outlet is connected to the tableView, which is of class UITableView. The TableView itself is sitting in the FiltersViewController object.
The FiltersViewController has the following interface:
#interface FiltersViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {}
The tableView's delegate and dataSource is connected to the File's-Owner. I implemented the required methods for table-setup...
What am I missing? I've read that ext_bad_access has to to with accessing pointers / objects that are no longer existing. I followed the basic rules for memory management, and cannot find an error in the code.
Help is really appreciated. pawi
Ha! I got it!
I got the tableView's delegate and dataSource connected to the TableViewController (of type FiltersViewController) instead to the File's-Owner...
This was lucky, it got me busy for over a day now. :-(
Cheerz!
You mean EXEC_BAD_ACCESS right?
It basically means you are trying to access an object which isn't there. like 15th object of an array which has only 10 objects for example.
Most probably you've done it in cellForRowAtIndexPath method where you're populating the table view cells.
try to set the break points any where that feel incomplete, such as u can set the break points on numberOfSection, build and debug it, so you know where u have to change..
I am trying to use CoreData to populate a UITableView. I have been using the developer "Locations" project, and I think I have everything correct. But, now I am getting the following error when I build:
request for member 'tableView' in something not a structure or union
Why would it be confused about tableView? I am using it many times in the methods. The errors seem to be coming from:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
Ideas?
That error tends to show up when you use dot-syntax in less than clear situations.
First, I would try changing it to [self tableView] and see if the issue goes away.
As for why it is occurring only in this method, more code would need to be shown to narrow down the specific issue.
Are you sure you're properly subclassing UITableViewController? As in,
#interface MyTableViewController : UITableViewController {}
EDIT: As Rob Lourens says, your problem is that you're subclassing UIViewController instead of UITableViewController. UIViewController has a generic view property, but no table view--use it for any situation where you don't need to manage a table view, and use UITableViewController for any situation where you do.
What is self and why do you need to use it there?
If you are in a class with a member named tableView, probably the only time you need to access it using self is when you create it to allow your #property (retain) to take effect. Sure it's not a bad idea to make accesses to members explicitly clear either.
(edit for eman - no worries!)