{"id":4489,"date":"2014-03-30T11:34:47","date_gmt":"2014-03-30T11:34:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-addsubview-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:34:47","modified_gmt":"2014-03-30T11:34:47","slug":"problem-about-addsubview-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-addsubview-collection-of-common-programming-errors\/","title":{"rendered":"problem about addsubview-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cf413aac057e188bcbabcdecdb78ff85?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSpontifixus<br \/>\nobjective-c addsubview<br \/>\n\/\/ ViewController.m1: &#8211; (IBAction)doNE:(id)sender { 2: 3: [self.view removeFromSuperview]; 4: [self.view addSubView:MasterViewController]; 4: }Error on line 4: &#8220;Unexpected interface name MasterViewController :expected expression&#8221;. I have two view controllers: ViewController and MasterViewController. I&#8217;ve set it up so that the first view is a ViewController but I&#8217;m trying to get a button to change the view.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/9R0Zu.jpg?s=32&amp;g=1\" \/><br \/>\njxdwinter<br \/>\nios subview addsubview<br \/>\neveryone.I have some labels that I draw them in the xib file, and add a background view using codes,but the background view is in the front of these labels, so I cant see them. So, my question is how can I add a background view below these labels.Thank you in advance.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/95b0c0231965a9f1e4aeb9c99af84758?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser157733<br \/>\nviews flip addsubview presentmodalviewcontrolle<br \/>\nHi I am writing an app in xcode 3.2.3. All I want to do is switch to another view but I am unsure of the best way to do this. I can do it either of these 2 ways&#8230;PreferencesViewController *screen = [[PreferencesViewController alloc]initWithNibName:nil bundle:nil];screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;[self presentModalViewController:screen animated:YES];[screen release];or using&#8230;PreferencesViewController *screen = [[PreferencesViewController alloc]initWithNibName:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/91fda86df3e9bf6177271f11915f73b5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRengers<br \/>\niphone uiviewcontroller addsubview<br \/>\nEDIT: Solved the problem myself. Turned out it was a leftover in the dealloc method that caused a UIButton to be released twice&#8230;I&#8217;m trying to display a UIViewController on top of another UIViewController like a popup. Problem is that the view seems to be getting overreleased. With NSZombieEnabled, I get the following error:[CALayer release]: message sent to deallocated instance 0x784bf40I use this code to add the view:\/\/self.someViewController is declared as (nonatomic, retain) self.someViewCo<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c62f123926bf959ca1454012f5bf833b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatthias Bauch<br \/>\nios for-loop subview addsubview<br \/>\nI have a question about the FOR loop and Subviews. I want to show a different SubView every time the loop runs with a different subview name. The name must be &#8220;hoofdstukController&#8221; + the i count. How can i do this? I tried a couple of methods but all crashed the app. This is my loop:_viewControllers = [[NSMutableArray alloc] init]; for (int i = 0; i &lt; 10; i++) {CGRect frame = _scrollView.frame;frame.origin.x = frame.size.width * i;frame.origin.y = 0; hoofdstukController.view.frame = frame;[_s<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ed8be7c906f7584a4dc3efa11a146db1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nkurisukun<br \/>\niphone memory viewcontroller addsubview<br \/>\nI realize that there are many questions similar to this one, but having looked through quite a bit of them, I still lack the confidence to know if what I&#8217;m doing is right. I apologize if this question is redundant, however I&#8217;d really like to nail down whether what I&#8217;m doing isn&#8217;t bad practice&#8230;To briefly summarize, I&#8217;m making a tool-like application, just for my testing. There is a UIToolbar on the bottom with a button. In terms of behavior, when the user clicks the button, it will open up a<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npoupou<br \/>\niphone ios garbage-collection monotouch addsubview<br \/>\nI have a MonoTouch tab view application. On one of my tabs, when a user clicks a button, I want to show another view. I do this with the following code:UIView.BeginAnimations(&#8220;flip&#8221;); UIView.SetAnimationDuration(1); UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight, View, true);NewFilesViewController newFilesViewController = new NewFilesViewController(); newFilesViewController.View.Frame = new System.Drawing.RectangleF(View.Frame.Top, this.View.Frame.Left, this.View.Frame.W<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fe8c1a45bd55600ad5957ceea0593df0?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nIrene<br \/>\niphone uiview uiimageview uiimage addsubview<br \/>\nI want to change an image on a view, from a popup dialog of 4-6 icons (imagine like changing your image on a messenger application). The way I implement this modal popup is by creating a new view at IB, with opacity on the background, and then I load this as a subview:IconsViewController *iconsViewController = [[IconsViewController alloc] initWithNibName:@&#8221;IconsView&#8221; bundle:nil]; [self.view addSubview:iconsViewController.view];So, when the user touches an icon, I have- (IBAction)iconIsSelected:(<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/a127b68167d05cb1688cc7845c531ea1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nPengOne<br \/>\nobjective-c ios uiapplicationdelegate addsubview retaincount<br \/>\nI was wondering something about the app delegate of my app. Why can&#8217;t I release like this :-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {RootViewController *controller = [[RootViewController alloc]initWithNibName:@&#8221;RootViewController&#8221;bundle:[NSBundle mainBundle]];[self.window addSubview:controller.view];[controller release]; \/\/ Here&#8217;s my question[self.window makeKeyAndVisible];return YES; }I was almost sure that -addSubview method inc<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f20e031b73538d1e796736f1e6979798?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKyle Parisi<br \/>\niphone xcode addsubview<br \/>\nI currently don&#8217;t have any problems using:-(IBAction)products:(id)sender {products = [[Products alloc] initWithNibName:@&#8221;Products&#8221; bundle:nil];[self.view addSubview:products.view]; }I tied this action to buttons to change my views. I&#8217;m sure this isn&#8217;t correct though because the views are being stacked right? Will my application crash because of this? Know of any good sample code to switch views via IBAction?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7676ccfa20c6a6ee704717aaabf6d75d?s=32&amp;d=identicon&amp;r=PG&amp;f=1\" \/><br \/>\nuser2732294<br \/>\niphone objective-c uiviewcontroller presentmodalviewcontrolle addsubview<br \/>\nI have added another view controller to a viewcontroller view ,addsubview works fine, but the button actions in next view are not working.crashes with an error [ModelViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0xa81d960in View1 : Current view controller UsersViewController class-(IBAction)openModelView:(id)sender {ModelViewController *modelView= [self.storyboard instantiateViewControllerWithIdentifier:@&#8221;ModelViewController&#8221;];[self.view addSubview:<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/38274ca62cae95ad2010c3d6d6191677?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nVince613<br \/>\niphone ios5 ios4.3 addsubview sigabrt<br \/>\nI was developing an app for iOS 4.3 back in the summer on my iPhone 4 and things were working well. I put that project on the back burner while I was relocating jobs. With the release of iOS 5 I updated both my Xcode and iOS SDK to 4.2 and 5.0 respectively and I also bought a new iPod Touch running 5.0 for developing.My app still works in the iPhone 4.3 Simulator (unfortunately I don&#8217;t have the iPhone 4 to test on anymore), but it crashes consistently on the iPhone 5.0 Simulator, as well as th<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/31850b6211b74e9b3ae9ef8af6785ec6?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\ndonald<br \/>\nios uiviewcontroller release addsubview<br \/>\nI have a very simple ViewController that contains the following:@interface ServingsView : UIViewController @property (retain, nonatomic) IBOutlet UILabel *labelTitle; @property (retain, nonatomic) IBOutlet UILabel *labelContent; @property (retain, nonatomic) IBOutlet UIButton *buttonSelect;I added no code to the m file of this controller.Now, I&#8217;m creating this viewcontroller and add its view to a scroll view:for (NSSubArray * Choice in currentItem.ItemsArray){stView * ChoiceView=[[stView alloc]i<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/925c69e3b631b0df38848844d26c3e5e?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser278859<br \/>\nios ipad ios5.1 addsubview<br \/>\nThe following works fine in 6.1 but the app crashes in 5.1&#8230;weeklyHeaderViewController =[[WeeklyHeaderViewController alloc] init]; [self.view addSubview:weeklyHeaderViewController.view];This is an iPad app and the view is 939&#215;31 .xib containing 7 UILabel pairs. The controller&#8217;r viewDidLoad method inserts a 4&#215;30 image seperator between the 7 pairs then moves the view into position at the bottom of the screen. I can trace it through the initWithNibName&#8217;s so it appears to be alloc ining fine. It c<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/25b02331ea03bb3408ed04bfa4a885af?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTim<br \/>\nobjective-c xcode addsubview<br \/>\nHello all I am having a issue with showing a xib file from the main file not sure why this is happening with some of the xib files and not others.if(segment == @&#8221;1&#8243;){Results1 *myView1 = [[Results1 alloc]initWithNibName:@&#8221;Results1&#8243; bundle:nil];[self.view addSubview:myView1.view]; }else if(segment == @&#8221;2&#8243;){Results2 *myView2 = [[Results2 alloc]initWithNibName:@&#8221;Results2&#8243; bundle:nil];[self.view addSubview:myView2.view]; }else if(segment ==@&#8221;3&#8243;){Results3 *myView3 = [[Results3 alloc]initWithNibName:@&#8221;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/YBbqr.jpg?s=32&amp;g=1\" \/><br \/>\nHaidro<br \/>\nios crash automatic-ref-counting addsubview<br \/>\nWhen I used tradition function[self.navigationController pushViewController:viewcontroller animated:YES];or [self presentModalViewController:viewcontroller animated:YES];,Everything is ok. But when I used [self.view addSubview:viewcontroller.view];I can&#8217;t do anything in next view, all view&#8217;s membory pointer has gone. And it crashes all the time.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/73abc5066c9d00d0d12a771d71f60960?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser2154750<br \/>\nios crash mkmapview addsubview<br \/>\nI&#8217;ve got a UIViewController that has been pushed onto a UINavigationController stack, which contains a single button with an &#8216;addMapToView&#8217; target. When I press the button, the app crashes, usually with no stack trace, but occasionally an [xxx barStyle] unrecognized selector stack trace, where xxx could be anything from an NSString to a UILabel or anything else.This behavior appeared with the recent update to iOS 7.0.3. I had apps in the queue waiting for review that I had to reject because of<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1c437be72cd736097f94160231e55699?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nManted<br \/>\nios uiviewcontroller popover addsubview<br \/>\nI&#8217;m doing an Ipad app. Now I have 2 viewcontrollers, ViewController has a button1 which has a popover segue to the second viewcontroller(PopoverController). Then, the PopoverController has a button2, if I click the button2, I&#8217;ll receive some UIImage from my server. I want to add fews subviews of UIImageView to the ViewController to display these images if I click the button2.The button1 works well, the PopoverController can pop up as expected. BUT when I click the button2, nothing happend. I wan<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/165a1e53fc013e63ed60d395bbf6ac6c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRob<br \/>\nios uiviewcontroller containers addsubview<br \/>\nI&#8217;m building a Custom Container ViewController to house several instances of a nib. This nib holds a ViewController subclassed as DemoViewController During the viewWillAppear of the Container, I perform the following:- (void) viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];NSLog(@&#8221;Container will appear&#8221;);if (_selectedViewController.parentViewController == self){\/\/ nowthing to doreturn;}DemoViewController *vc = [[DemoViewController alloc] initWithNibName:@&#8221;Gauge&#8221; bundle:nil];NSArr<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/181035f8aac1cb68d50dc58b67dc0349?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMischa<br \/>\nios addsubview parentviewcontroller container-view childviewcontroller<br \/>\nI want to add a tableViewController as a child view controller of a containerViewController (shown below). According to Apple&#8217;s View Controller Programming Guide I can achieve this by the following lines of code inside my containerViewController:[self addChildViewController:tableViewController];[self.view addSubview:tableViewController.view];[tableViewController didMoveToParentViewController:self];In fact, that works fine. Now the problem is that I do not want to add the tableViewController&#8217;s vi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/81bb162cf5af451c67c13137b3db15f5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDanielH<br \/>\nios subview iboutlet addsubview<br \/>\nI am newbie in iOS development and I have a problem to understand file owner logic.I have this situations:I have two views (View_iPad, View_iPhone) and their controllers (ViewController_iPad, ViewController_iPhone). Based on a device where app is launched, particular view and its controller is used. Then, I add a subview from xib file to this view (it doesn&#8217;t matter if iPad or iPhone view is used). Let&#8217;s say that there is a different position of this subview in iPad and iPhone view. This subview<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cfb10c3abf0d9f3b73a76d6932c39fb3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFelwah<br \/>\nxcode drag-and-drop addsubview<br \/>\nI&#8217;m working on drag and drop app, when the user drop an image, I want to make copy from it in the drapped point, and then the original one returns to it initial point. I decided to add uiimageview to my viewcontroller after performing touchesEnded, I have drag view class containing the method : &#8211; (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {CGPoint activePoint = [[touches anyObject] locationInView:self]; UIImageView *myimage; myimage.image = self.image; myimage.center = acti<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spontifixus objective-c addsubview \/\/ ViewController.m1: &#8211; (IBAction)doNE:(id)sender { 2: 3: [self.view removeFromSuperview]; 4: [self.view addSubView:MasterViewController]; 4: }Error on line 4: &#8220;Unexpected interface name MasterViewController :expected expression&#8221;. I have two view controllers: ViewController and MasterViewController. I&#8217;ve set it up so that the first view is a ViewController but I&#8217;m trying to get a button to change [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4489","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4489"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4489\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}