ext_bad_access when trying to show a tableView - iphone

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..

Related

How to reload the UIViewController

Can anyone please tell me how to reload the view.In my program,it contain a tab view controller.There is one item named "A" in the tab.And this "A" item is pointing to a viewController.In that view Controller, it is displaying some datas and I have included UIActionSheet in that. There is one button-Delete in the actionsheet.This delete button is for deleting the particular data.Now my problem is that I need to reload that view so that these deleted data should not be displayed. So anyone please tell me how to reload the page. I have included the following code before
[self presentModalViewController:historyView animated:YES];
[historyView setNeedsDisplay];
but it is showing some error :-
No visible #interface for viewcontroller declares the selector 'setNeedsDisplay'
Please tell me the solution.. :(
UIViewController class doesn't have a method setNeedsDisplay. The UIView class does have this method. So you can write like that:
[historyView.view setNeedsDisplay];
But this method doesn't reload a view. It just marks the receiver’s entire bounds rectangle as needing to be redrawn (from apple documentation iOS Developer Library). So as a result the drawRect method will be called.
To solve your problem you can create your own function like initializeUI in your view controller and then call it when the view is loaded initially (in viewDidLoad method) and for example after deleting the data when you need the view to be updated.

UITableViewController loading inside a UIViewController inside a UIViewController issue

I don't really know if what I'm doing is the right way to do it. Right now it seems to be working until it hits a certain point with a EXC_BAD_ACCESS message.
I'll describe what I'm doing as best and with the most relevant details I can tell:
I have a CalendarViewController that inherits UIViewController which is loading from a .xib file (CalendarViewController.xib). The class contains a UIView called contentView which I created and which I initialize with another nib file based on a class which is also inherited from UIViewController:
- (void)viewDidLoad {
[super viewDidLoad];
calendarView = [[CalendarView alloc] initWithNibName:#"CalendarView" bundle:nil];
[contentView addSubview:calendarView.view];
}
(calendarView is the class inheriting UIViewController and viewDidLoad is from CalendarViewController.
CalendarView.xib has a UITableViewController with it's respective UITableView. This Table View Controller is linked to a CalendarTableController to which I also generated a .xib file for it.
Everything is being created just right (apparently) but it is crashing somewhere very unexpected. CalendarTableController also implements a DateLoaderDelegate which loads information from an xml on an external url.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// When the data has all finished loading, we set a copy of the
// loaded data for us to access. This will allow us to not worry about
// whether a load is already in progress when accessing the data.
self.lastLoadedMatchXMLData = [self.matchXMLData copy];
// Make sure the _delegate object actually has the xmlDidFinishLoading
// method, and if it does, call it to notify the delegate that the
// data has finished loading.
if ([_delegate respondsToSelector:#selector(xmlDidFinishLoading)])
{
[_delegate xmlDidFinishLoading];
}
}
The application is getting to this point without any problem. _delegate is containing the correct object (a CalendarTableController which implements the DateLoaderDelegate). But when it arrives to the line:
if ([_delegate respondsToSelector:#selector(xmlDidFinishLoading)])
it crashes with the EXC_BAD_ACCESS, I don't really know the reason, if I look at the debugger, the crash is not occurring in any of my classes as any of them are appearing in the execution stack. URLConnectionClient seems to be generating it, but I don't really know why. The loading of the xml had worked earlier before I rearranged the ViewControllers to work as I have described now.
Any ideas?
It's weird. I fixed the problem but I had to dedicate the whole UIViewController to contain the UITableView. What I did was this:
Create an IBOutlet with the custom UITableViewController (CalendarTableViewController) in the custom UIViewController.
In the loaded .xib file I linked the IBOutlet to a created UITableViewController declared as a CalendarTableViewController.
This way I solved the problem of the UITableViewController being deallocated without reason. But now the image views I had placed in the intermediate UIViewController wouldn't appear. I had to set that UIViewController to contain solely the CalendarTableView and place the image views in the initial UIViewController. Weird, isn't it? I don't like much the hierarchy I created... but for now that will do =S
Check that you have defined properties for all of your subviews and that you are retaining everything that you need to be. Bad Access May mean that you're attempting to call respondsToSelector on an object that has been released.
Have you tried calling loadView before adding the nested controller's view to the parent's view?
Maybe viewDidLoad is not executing before you add the view and some variables were never initialized.

iOS / Xcode 4: View won't load

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.

How do you use reloadData?

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

Passing info to a delegate from a UIActionSheet

My understanding about passing data back to a delegate completely revolves around making a new view controller and having it conform to a protocol.
I am trying to get a time input back from a UIDatePicker set with the UIDatePickerModeCountDownTimer mode and I am running into issues.
Inside of Main1.m I create a UIActionSheet *action, and set everything up so that it presents itself with a UIDatePicker on a click. Inside of Main.m I also say:
main.delegate = self;
If this were not a UIActionSheet, I would make a protocol reference inside the new ViewController and then have the new vc pass data to a method that Main has, but I can't do that with a UIActionSheet!!
What am I missing? I assume there is something inherently different about Action Sheets, ut I can't figure it out.
Thanks for your help!!!
EDIT:
Sorry! I was giving a generic name to my view controller. It isn't actually Main.m, its FirstViewController.h/m
I didn't realize that my generic reference was getting mixed up with the Main.m file that is completely different than a vc.
I don't exactly understand why you're putting your delegate assignment in Main.m. I assume that you're setting up your UIActionSheet in a ViewController, and launching it from there. In this case, your ViewController is your delegate object. So you need to make sure that your ViewController implements the UIActionSheetDelegate. ie:
#interface SomeController : UIViewController <UIActionSheetDelegate>
Then you simply implement the required methods of that delegate in your view controller class, and that should do it. If I'm missing something about how you're implementing this, then you need to provide more code examples to examine.