I added a subview to my main view, the subview has a button on it, but when I select the button on the subview, the application crashes with the following highlited in green:
Thread 1:EXC_BAD_ACCESS (code=1), address=0xf0000008
The subview has its own viewcontroller and xib file.
heres some of the code I used:
Subview.h
- (IBAction)setDummyTime:(id)sender;
Main view.m
PickupTimeViewController *pickupTimeView = [[PickupTimeViewController alloc]init];
[selectedView addSubview:pickupTimeView.view];
Thanks
Sounds like its been dealloc'ed on you.
Try turning on Zombie mode, crash the app again and see if it points you to whats going on, it will tell which object is trying to do something after being released.
Xcode -> Click your scheme -> Edit Scheme -> Run -> Diagnostics -> Tick Enable Zombie Objects
Another thing to try is to watch your subView in the debug area, this will tell you when your subView is released.
Example of setting watch
Also if you have not already tried it, try keep a strong/retain reference to your subview.
If you can't get it working post the code you create the view with.
EDIT:
in .h
#property (nonatomic, strong) PickupTimeViewController *pickupTimeView;
in .m
self.pickupTimeView = [[PickupTimeViewController alloc]init];
[selectedView addChildViewController:self.pickupTimeView]; // (i0S5+ only) if the view you add to is a view controller if not use self otherwise.
[selectedView addSubview:pickupTimeView.view];
Good luck,
BooRanger
Related
I am trying trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
I am 99% done with copying this code, but I just have one final problem. I have an IBOutlet statement that looks like this: #property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
According to the Apple sample code, this outlet is supposed to be connected to a View object that has been placed on top of the normal/default view.
Here is a screenshot of what the Connections Inspector looks like in the Apple example:
You will notice that the IBOutlet called "previewView" has been connected to something called the "Cam Preview View".
Also, in this screenshot, you can see that I am able to select this View object by itself and that it shows a Referencing Outlet in it's connections inspector for the same IBOutlet and View Object:
My problem is that I cannot get the IBOutlet code to connect to this View Object. I have tried the normal behavior of clicking and dragging to make the connections but it just wants to create a new outlet. It will not let me connect to the outlet that I have already created.
I have been playing with this for 2 hours now and just can't get it to work like Apple's sample code.
Any help is greatly appreciated thank you.
In your .xib file, make sure that UIView class is assigned as AVCamPreviewView instead of UIView.
A few possible solutions:
Save the file with the IBOutlet you're trying to connect up (the source code, not the IB)
Clean, rebuild
Restart Xcode.
I know it is possible to connect an object in a XiB file (i.e button) and connect it to any viewController. I am also able to go to that viewController and programmatically set properties to that object(everything autocompletes fine, it recognizes the object properties) However, when I run the app, the button is unchanged, what gives?
Is there something I'm missing? Is there an additional step that I need to do when using a ViewController that is not the .m file related to the XIB?
Here's part of the code... I don't get any errors!
user.default_sales_rep_id = 2;
if (user.default_sales_rep_id > 0) {
buttonMask.backgroundColor = [UIColor blackColor];
}
You are most likely setting the properties on the button too early. Since you don't specify in your question where this code is located, it's hard to say but I'd guess if you put your code in awakeFromNib it would work.
- (void)awakeFromNib {
[super awakeFromNib];
//code here
}
Any changes to your view that differ from your XIB should be done in this method as it is called after the view is set up from the XIB.
Are you certain you are calling [[UIButton alloc] init] before you attempt manipulating it? I assume you have the button already as an IBOutlet, but if I recall, if you wish to make custom changes to the button, you must still do this.
(originally i posted this on Apple Developer Network and got no response in four days, so i am copy/pasting here)
ARC is enabled.
In my class i have an UITableViewController property,
#property (nonatomic, strong) UITableViewController* tableViewControllerSectionMenu;
which is used to hold table view for UIPopoverController.
This code creates UITableViewController and sets delagate and data source in viewDidLoad:
self.tableViewControllerSectionMenu = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
self.tableViewControllerSectionMenu.tableView.dataSource = self.dataSource;
self.tableViewControllerSectionMenu.tableView.delegate = self;
This works fine until memory warning occur.
After that the table is blank.
I tried putting reloadData at place where popover is invoked but that changes nothing.
Does somebody know why this is happening and how to remedy this?
By googling i have found several solutions and none have worked in my case.
I think your data is cleaned when the memory warning is received. Did you implement either didReceiveMemoryWarning or viewDidUnload by any chance?
When memory warning message is received, all views not currently visible on screen are purged. They are supposed to be recreated later when needed.
To recreate them means also to attach delegate and data source again. Since memory warning was received while in ViewController X, and it's view was on screen, my table view got purged.
But as i wasn't moving from X, delegate and data source were not attached again, as that was done in viewDidLoad.
To evade getting back one step from X, i created a new class for my table view where in viewDidLoad i attached delegate and data source.
I have an app, with a lot of views and subviews.
In my app delegate, I open a subview each time I receive a notification.
I made a lot of tests :
- the notifications are always received well.
- the subview is always well created, it's never at nil.
But after a notification or two, the subviews do not show again, even if they exist and are well created in memory.
I think I am doing something wrong with the memory and I probably misunderstood something with the view hierarchy.
Here is the code that create and add the subview :
AppDelegate.h
#property (retain, nonatomic) ViewControllerNewOrder *sub;
AppDelegate.m
sub = [[ViewControllerDriverNewOrder alloc] init];
sub = [mainStoryboard instantiateViewControllerWithIdentifier:#"ViewControllerNewOrder"];
sub.view.frame = self.initialViewController.view.bounds;
[self.initialViewController.view addSubview:sub.view];
Thank you for your time and your help !
The following line saved my life :
[self.window.rootViewController.view.subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
Then I added the method removeFromSuperView to all the views I needed to clear.
Of course, you will need, like me, to think about where you place this line.
Thanks ;)
I'm trying to add a Modal ViewController to the existing application. To init and open it I use the following code
AddedViewController *addedOne = [[AddedViewController alloc] init];
[self.parent presentModalViewController:addedOne animated:YES];
If AddedViewController.xib with a View inside of course is just empty it opens nicely,
but
This throws SIGTRAP signal ((lldb) in log) at loading if AddedViewController.xib is not empty (i.e.) even if I add just a UILabel with static text there.
How can I handle this to have fully-operational ViewController (with labels, buttons, textfields, etc.. open properly?
========
UPD.
Problem easily resolved, see my answer below. =)
Assuming you are trying to present this inside the current view, you should not use self.parent and just use self.
The answer was in Use Autolayout checkbox for the ViewController settings, now everything works fine TWIMC. =))