Search Results

Search found 396 results on 16 pages for 'dealloc'.

Page 6/16 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • How load WebView with another URL when navigated through tab bar viewController

    - by TechFusion
    Hello, I have created window based application, root controller as Tab bar controller. WebView is being loaded in Tab bar interfaced ViewController's View.WebView is created using IB.WebView object declared in ViewController as per below. //ViewController.h @interface ViewController:UIViewController{ IBOutlet UIWebview *Webview; } @property(nonatomic,retain)IBOutlet UIWebview *Webview; @end I am calling [WebView loadrequest] method in -viewDidLoad method and stopLoading will be called in -viewWillDisappear method. I am again reload it in -viewWillAppear:animated method to load it again when tab bar is pressed. //ViewController.m @implementation viewcontroller @synthesize Webview; -(void)viewDidLoad{ [super viewDidLoad]; [self.Webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.apple.com"]]]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.Webview reload]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.Webview stopLoading]; } I am releasing WebView in -ViewDidUnload method -(void)viewDidUnload{ [super viewDidUnload]; [Webview release]; } -(void)dealloc{ [Webview release]; [super dealloc]; } Does Webview released correctly ? Here how to kill connection with URL when ViewWillDisappear method called ? How to load View with Different URL then it's loaded in -viewDidLoad method when ViewController interfaced tab is pressed ? Means if naviagated from one tab to another that ViewController interface tab which has WebView should load request with another URL. Does it correct to call [self.Webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"www.stackoverflow.com"]]]; this method again in -viewWillAppear:animated method to load with another URL ? Thanks,

    Read the article

  • UIViewerTableViewController.m:15: error: expected identifier before '*' token

    - by Aaron Levin
    I am new to objective-c programming. I come from a C# background. I am having problems with the following code I am writing for a proof of concept for an iPhone App: I am getting a number of compile errors but I think they are all due to the first error (could be wrong) - error: expected identifier before '*' token (@synthesize *lists; in the .m file) I'm not sure why my code is showing up the way it is in the view below the editor..hmm any way, any help would be appreciated. .m file // // Created by Aaron Levin on 4/19/10. // Copyright 2010 RonStan. All rights reserved. // import "UIViewerTableViewController.h" @implementation UIViewerTableViewController @synthesize *lists; @synthesize *icon; (void)dealloc { [Lists release]; [super dealloc]; } pragma mark Table View Methods //Customize number of rows in table view (NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection: (NSInteger) section{ return self.Lists.Count; } //Customize the appearence of table view cells (UITableViewCell *) tableView(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath{ static NSString *CellIdentifier = @"Cell"; UITableView *Cell = [tablevView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [[self.Lists objectAtIndex:indexPath.row] retain]; cell.imageView = self.Icon; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } @end .h file // // UIMyCardsTableViewController.h // MCS ProtoType v0.1 // // Created by Aaron Levin on 4/19/10. // Copyright 2010 RonStan. All rights reserved. // import @interface UIViewerTableViewController : UITableViewController { NSArray *lists; UIImage *icon; } @property (nonatomic,retain) NSArray *lists; @property (nonatomic,retain) UIImage *icon; @end

    Read the article

  • array retain question

    - by Cosizzle
    Hello, im fairly new to objective-c, most of it is clear however when it comes to memory managment I fall a little short. Currently what my application does is during a NSURLConnection when the method -(void)connectionDidFinishLoading:(NSURLConnection *)connection is called upon I enter a method to parse some data, put it into an array, and return that array. However I'm not sure if this is the best way to do so since I don't release the array from memory within the custom method (method1, see the attached code) Below is a small script to better show what im doing .h file #import <UIKit/UIKit.h> @interface memoryRetainTestViewController : UIViewController { NSArray *mainArray; } @property (nonatomic, retain) NSArray *mainArray; @end .m file #import "memoryRetainTestViewController.h" @implementation memoryRetainTestViewController @synthesize mainArray; // this would be the parsing method -(NSArray*)method1 { // ???: by not release this, is that bad. Or does it get released with mainArray NSArray *newArray = [[NSArray alloc] init]; newArray = [NSArray arrayWithObjects:@"apple",@"orange", @"grapes", "peach", nil]; return newArray; } // this method is actually // -(void)connectionDidFinishLoading:(NSURLConnection *)connection -(void)method2 { mainArray = [self method1]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { mainArray = nil; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [mainArray release]; [super dealloc]; } @end

    Read the article

  • NSCollectionView subclass doesn't call drawRect during drag session despite setNeedsDisplay

    - by Alain Vitry
    Greetings, I am puzzled as to how and when drawRect is supposed to be called in a NSCollectionView subclass. I implement drag and drop operation in order to move NSCollectionViewItems within the collection, and would like to draw a visual indication of where the drop would end. The subclass does not call drawRect during the drag session. (It does during scroll) Is this the intended operation ? Any hint on how to implement this behavior properly are welcome. A full xcode project of the following code is available at: http://babouk.ovh.org/dload/MyCollectionView.zip Best regards Code sample: @interface CollectionViewAppDelegate : NSObject <NSApplicationDelegate> { NSWindow *window; NSMutableArray *collectionContent; } /* properties declaration */ /* KVC compliance declarations */ @end @interface MyCollectionView : NSCollectionView @end @interface ItemModel { NSString *name; } @property (copy) NSString *name; @end @implementation MyCollectionView - (void)drawRect:(NSRect)rect { NSLog(@"DrawRect"); } - (void)mouseDragged:(NSEvent *)aEvent { NSPoint localPoint = [self convertPoint:[aEvent locationInWindow] fromView:nil]; [self dragImage:[NSImage imageNamed:@"Move.png"] at:localPoint offset:NSZeroSize event:aEvent pasteboard:nil source:self slideBack:NO]; } - (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender { return YES; } - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { return NSDragOperationEvery; } - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender { [self setNeedsDisplay:YES]; return NSDragOperationEvery; } - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { return NSDragOperationEvery; } - (void)mouseDown:(NSEvent *)theEvent { } @end @implementation CollectionViewAppDelegate @synthesize window, collectionContent, collectionView; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSMutableArray *data = [[NSMutableArray alloc] init]; /* Fill in data */ [self setCollectionContent:data]; [data release]; } /* dealloc */ /* KVC implementation */ @end @implementation ItemModel @synthesize name; /* dealloc */ @end

    Read the article

  • UINavigationController crash because of pushing and poping UIViewControllers

    - by Wayne Lo
    My question is related to my discovery of a reason for UINavigationController to crash. So I will tell you about the discovery first. Please bare with me. The issue: I have a UINavigationController as as subview of UIWindow, a rootViewController class and a custom MyViewController class. The following steps will get a Exc_Bad_Access, 100% reproducible.: [myNaviationController pushViewController:myViewController_1stInstance animated:YES]; [myNaviationController pushViewController:myViewController_2ndInstance animated:YES]; Hit the left back tapBarItem twice (pop out two of the myViewController instances) to show the rootViewController. After a painful 1/2 day of try and error, I finally figure out the answer but also raise a question. The Solutio: I declared many objects in the .m file as a lazy way of declaring private variables to avoid cluttering the .h file. For instance, #impoart "MyViewController.h" NSMutableString*variable1; @implement ... -(id)init { ... varialbe1=[[NSMutableString alloc] init]; ... } -(void)dealloc { [variable1 release]; } For some reasons, the iphone OS may loose track of these "lazy private" variables memory allocation when myViewController_1stInstance's view is unloaded (but still in the navigation controller's stacks) after loading the view of myViewController_2ndInstance. The first time to tap the back tapBarItem is ok since myViewController_2ndInstance'view is still loaded. But the 2nd tap on the back tapBarItem gave me hell because it tried to dealloc the 2nd instance. Executing [variable release] resulted in Exc_Bad_Access because it pointed randomly (loose pointer). To fix this problem is simple, declare variable1 as a @private in the .h file. Here is my Question: I have been using the "lazy private" variables for quite some time without any issues until they are involved in UINavigationController. Is this a bug in iPhone OS? Or there is a fundamental misunderstanding on my part about Objective C? Please help.

    Read the article

  • Save UIwebview contents to photo gallery

    - by user307410
    There's a video tutorial on u tube that shows how to perform this.It consists of a UIwebview and toolbar button to save the contents.Haven't had any luck making this work.Could someone have a look and see they can make it work.Many thanks in advance. http://www.youtube.com/watch?v=gDPca3JIc_s&feature=player_embedded# /////////////////////////////////////////////////////////////////// // // SaveWebViewController.h // SaveWeb // // // Copyright MyCompanyName 2010. All rights reserved. // import @interface SaveWebViewController : UIViewController { IBOutlet UIWebView *webview; } @property (nonatomic, retain) IBOutlet UIWebView *webview; [IBAction]saveWeb:(id)sender; @end //////////////////////////////////////////////////////////////////////////////// // // SaveWebViewController.m // SaveWeb // // // Copyright MyCompanyName 2010. All rights reserved. // import "SaveWebViewController.h" @implementation SaveWebViewController (IBAction)saveWeb:(id)sender { UIGraphicsBeginImageContext(webView.frame.size); [self.view.layer renderInContext: UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); } // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } //Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]]; } // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } (void)dealloc { [super dealloc]; } @end

    Read the article

  • OCUnit & NSBundle

    - by kpower
    I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test: // myClass.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface myClass : NSObject { UIImage *image; } @property (readonly) UIImage *image; - (id)initWithIndex:(NSUInteger)aIndex; @end // myClass.m #import "myClass.m" @implementation myClass @synthesize image; - (id)init { return [self initWithIndex:0]; } - (id)initWithIndex:(NSUInteger)aIndex { if ((self = [super init])) { NSString *name = [[NSString alloc] initWithFormat:@"image_%i", aIndex]; NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"]; image = [[UIImage alloc] initWithContentsOfFile:path]; if (nil == image) { @throw [NSException exceptionWithName:@"imageNotFound" reason:[NSString stringWithFormat:@"Image (%@) with path \"%@\" for current index (%i) wasn't found.", [name autorelease], path, aIndex] userInfo:nil]; } [path release]; } return self; } - (void)dealloc { [image release]; [super dealloc]; } @end And my unit-test (LogicTests target): // myLogic.m #import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> #import "myClass.h" @interface myLogic : SenTestCase { } - (void)testTemp; @end @implementation myLogic - (void)testTemp { STAssertNoThrow([[myClass alloc] initWithIndex:0], "myClass initialization error"); } @end All necessary frameworks, "myClass.m" and images added to target. But on build I have an error: [[myClass alloc] initWithIndex:0] raised Image (image_0) with path \"(null)\" for current index (0) wasn't found.. myClass initialization error This code (initialization) works fine in application itself (main target) and later displays correct image. I've also checked my project folder (build/Debug-iphonesimulator/LogicTests.octest/) - there are LogicTests, Info.plist and necessary image files (image_0.png is one of them). What's wrong?

    Read the article

  • UISearchDisplayController "shouldReloadTableForSearchString return NO" reloads table

    - by Jeena
    Why does my UISearchDisplayController show "No results" even if the shouldReloadTableForSearchString method returns NO? Shouldn't it just do nothing and stay black? How can I prevent it from doing so? #import "RootViewController.h" #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.searchDisplayController.searchResultsTableView) { return 0; } return 10; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row]; return cell; } #pragma mark SearchController stuff - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { return NO; } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • drawing different quartz 2d

    - by Cosizzle
    Hello, I'm trying to make a small application or demo thats a tab bar application. Each bar item loads in a new view. I've created a quartzView class that is called on by the controller: - (void)viewDidLoad { quartzView *drawingView = [[quartzView alloc] initWithFrame:CGRectMake(0,0,320,480)]; [self.view addSubview:drawingView]; [super viewDidLoad]; } From my understanding, the drawRect method must be triggered in order to render the object and to draw it. This is my quartzView class: #import "quartzView.h" @implementation quartzView #pragma mark shapes // Blue Circle - (void)drawRect:(CGRect)rect { NSLog(@"Trying to draw..."); CGContextRef ctx = UIGraphicsGetCurrentContext(); //get the current context CGContextClearRect(ctx, rect); //clear off the screen //draw a red square CGContextSetRGBFillColor(ctx, 255, 0, 0, 1); CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50)); } // ==================================================================================================== #pragma mark - - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code } return self; } - (void)dealloc { [super dealloc]; } @end So how would I go about to say, if the view is view one, draw a square if it's view two draw a circle. And so on.

    Read the article

  • Unable to access a primitive array inside a custom class from a UIViewController instance

    - by Daniel
    Hello! I have made a subclass of NSObject that is meant to be the model of my application. The class has a few methods and on instance primitive array as such: @interface Cube : NSObject { int cubeState[5][2][2]; } - (id)printContent; @end @implementation Cube - (void)init { if (self = [super init]) { for (int i=0; i<=5; i++) { for (int j=0; j<=2; j++) { for (int k=0; k<=2; k++) { cubeState[i][j][k] = i; } } } } return self; } - (void)printContent { for (int i=0; i<=5; i++) { for (int j=0; j<=2; j++) { for (int k=0; k<=2; k++) { NSLog(@"[%d] [%d] [%d] = %d", i, j, k, cubeState[i][j][k]); } } } } @end This works fine if instanciated from the delegate as such: #include "Cube.h" @implementation CubeAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { Cube *cube = [[Cube alloc] init]; [cube printContent]; [cube release]; [window makeKeyAndVisible]; } However, the application crashes if I try to create a subclass of UIViewController with a Cube *cube property and later try to access the Cube instance object through the view controller's property as such: @interface CustomController : UIViewController { Cube *cube; } @property (nonatomic, retain) Cube *cube; @end @implementation CustomController @synthesize cube; - (void)dealloc { [cube release]; [super dealloc]; } @end and in the delegate: - (void)applicationDidFinishLaunching:(UIApplication *)application { viewController = [[CustomController alloc] initWithNibName:@"MainView" bundle:nil]; viewController.cube = [[[Cube alloc] init] autorelease]; [viewController.cube printContent]; // Application crashes here } Any ideas?

    Read the article

  • Scrolling with two fingers with a UIScrollView

    - by Craig
    I have an app where my main view accepts both touchesBegan and touchesMoved, and therefore takes in single finger touches, and drags. I want to implement a UIScrollView, and I have it working, but it overrides the drags, and therefore my contentView never receives them. I'd like to implement a UIScrollview, where a two finger drag indicates a scroll, and a one finger drag event gets passed to my content view, so it performs normally. Do I need create my own subclass of UIScrollView? Here's my code from my appDelegate where I implement the UIScrollView. @implementation MusicGridAppDelegate @synthesize window; @synthesize viewController; @synthesize scrollView; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch //[application setStatusBarHidden:YES animated:NO]; //[window addSubview:viewController.view]; scrollView.contentSize = CGSizeMake(720, 480); scrollView.showsHorizontalScrollIndicator = YES; scrollView.showsVerticalScrollIndicator = YES; scrollView.delegate = self; [scrollView addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [scrollView release]; [window release]; [super dealloc]; }

    Read the article

  • how to load multiple images in iCarousel using this code?

    - by Dany
    i'm loading bunch of images in coverflow using i carousel but i'm not getting it?..initially i got Signal sigabart issue..after i edited some of the code the view gets displayed...Am i missing something?... #import "CollectionViewController.h" @interface CollectionViewController () @property (nonatomic, retain) NSMutableArray *items; @end @implementation CollectionViewController @synthesize carousel; @synthesize items; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)dealloc { carousel.delegate = nil; carousel.dataSource = nil; [items release]; [carousel release]; [super dealloc]; } - (void)viewDidLoad { [super viewDidLoad]; carousel.type = iCarouselTypeCoverFlow2; } - (void)viewDidUnload { [super viewDidUnload]; self.carousel = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } #pragma mark - #pragma mark iCarousel methods - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel { return [items count]; } - (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel { return 29; } - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view { //create new view if no view is available for recycling if (view == nil) { view = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"], [UIImage imageNamed:@"gal2.jpg"], [UIImage imageNamed:@"gal3.jpg"], [UIImage imageNamed:@"gal5.jpg"], [UIImage imageNamed:@"gal6.jpg"], [UIImage imageNamed:@"gal7.jpg"], [UIImage imageNamed:@"gal8.jpg"], [UIImage imageNamed:@"gal9.jpg"], [UIImage imageNamed:@"gal10.jpg"], [UIImage imageNamed:@"gal11.jpg"], [UIImage imageNamed:@"gal12.jpg"], [UIImage imageNamed:@"gal13.jpg"], [UIImage imageNamed:@"gal14.jpg"], [UIImage imageNamed:@"gal15.jpg"], [UIImage imageNamed:@"gal16.jpg"], [UIImage imageNamed:@"gal17.jpg"], [UIImage imageNamed:@"gal18.jpg"], [UIImage imageNamed:@"gal19.jpg"], [UIImage imageNamed:@"gal20.jpg"], [UIImage imageNamed:@"gal21.jpg"], [UIImage imageNamed:@"gal22.jpg"], [UIImage imageNamed:@"gal23.jpg"], [UIImage imageNamed:@"gal24.jpg"], [UIImage imageNamed:@"gal25.jpg"], [UIImage imageNamed:@"gal26.jpg"], [UIImage imageNamed:@"gal27.jpg"], [UIImage imageNamed:@"gal28.jpg"], } else { } return view; } @end while running on simulator i just get the screen not images?...i got stuck here....

    Read the article

  • Why isn’t my autoreleased object getting released?

    - by zoul
    Hello. I am debugging a weird memory management error and I can’t figure it out. I noticed that some of my objects are staying in memory longer than expected. I checked all my memory management and finally got to the very improbable conclusion that some of my autorelease operations don’t result in a release. Under what circumstances is that possible? I created a small testing Canary class that logs a message in dealloc and have the following testing code in place: NSLog(@"On the main thread: %i.", [NSThread isMainThread]); [[[Canary alloc] init] autorelease]; According to the code we’re really on the main thread, but the dealloc in Canary does not get called until much later. The delay is not deterministic and can easily take seconds or more. How is that possible? The application runs on a Mac, the garbage collection is turned off (Objective-C Garbage Collection is set to Unsupported on the target.) I am mostly used to iOS, is memory management on OS X different in some important way?

    Read the article

  • my MKAnnotationVIew is not showing the title

    - by hydev
    Hi, I am new to iPhone programming and I can't understand why the MKAnnotationView is not showing the title's of my annotation's. Below is the code that is used to display it on the map. - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views { NSLog(@"Entered didAddAnnotationViews"); MKAnnotationView *annotationView = [views objectAtIndex:0]; id <MKAnnotation> mp = [annotationView annotation]; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250); [mv setRegion:region animated:YES]; } Here is where I am defining my annotations: MapPoint *mp = [[MapPoint alloc] initWithCoordinate:[newLocation coordinate] title:[locationTitleField text]]; [mapView addAnnotation:mp]; [mp release]; mp is a class I have created to keep track of all the map points: #import "MapPoint.h" @implementation MapPoint @synthesize coordinate, title; - (id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t { [super init]; coordinate = c; [self setTitle:t]; return self; } - (void)dealloc { [title release]; [super dealloc]; } @end I am beginner so go easy, and all help greatly appreciated. Mike

    Read the article

  • Instruments (Leaks) and NSDateFormatter

    - by Cal
    When I run my iPhone app with Instruments Leaks and parse a bunch of NSDates using NSDateFormatter my memory goes up about 1mb and stays even though these NSDates should be dealloc'd after the parsing (I just discard them if they aren't new). I thought the malloc (in my heaviest stack trace below) could become part of the NSDate but I also thought it could be memory that only used during some intermediate step in parsing. Does anyone know which one it is or how to find out? Also, is there a way to put a breakpoint on NSDate dealloc to see if that memory is really being reclaimed? Here's what my date formatter looks like for parsing these dates: df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"EEE, d MMM yyyy H:m:s z"]; Here's the Heaviest Stack trace when the memory bumps up and stays there: 0 libSystem.B.dylib 208.80 Kb malloc 1 libicucore.A.dylib 868.19 Kb icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&) 2 libicucore.A.dylib 868.66 Kb icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&) 3 libicucore.A.dylib 868.67 Kb icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&) 4 libicucore.A.dylib 868.67 Kb icu::DateFormatSymbols::initZoneStringFormat() 5 libicucore.A.dylib 868.67 Kb icu::DateFormatSymbols::getZoneStringFormat() const 6 libicucore.A.dylib 868.67 Kb icu::SimpleDateFormat::subParse(icu::UnicodeString const&, int&, unsigned short, int, signed char, signed char, signed char*, icu::Calendar&) const 7 libicucore.A.dylib 868.67 Kb icu::SimpleDateFormat::parse(icu::UnicodeString const&, icu::Calendar&, icu::ParsePosition&) const 8 libicucore.A.dylib 868.67 Kb icu::DateFormat::parse(icu::UnicodeString const&, icu::ParsePosition&) const 9 libicucore.A.dylib 868.67 Kb udat_parse 10 CoreFoundation 868.67 Kb CFDateFormatterGetAbsoluteTimeFromString 11 CoreFoundation 868.67 Kb CFDateFormatterCreateDateFromString 12 Foundation 868.67 Kb -[NSDateFormatter getObjectValue:forString:range:error:] 13 Foundation 868.75 Kb -[NSDateFormatter getObjectValue:forString:errorDescription:] 14 Foundation 868.75 Kb -[NSDateFormatter dateFromString:] Thanks!

    Read the article

  • Custom UIButton for Iphone.

    - by Amal
    I have an view in my App which has a number of buttons based on the number of items returned by the server. So if the server returns say 10 items, there should be 10 buttons and clicking on each button should call a different person. For the above purpose I created a custom button class deriving from UIButton. @implementation HopitalButton @synthesize index; @synthesize button_type; - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { UIImage* img = [UIImage imageNamed:@"dr_btn.png"]; [img stretchableImageWithLeftCapWidth:10 topCapHeight:10]; [self setBackgroundImage:img forState:UIControlStateNormal]; [self setTitleColor:[UIColor colorWithRed:0.698 green:0.118 blue:0.376 alpha:1] forState:UIControlStateNormal] ; [self setFont:[UIFont fontWithName:@"Helvetica Bold" size:13]]; self.titleLabel.textColor = [UIColor colorWithRed:178 green:48 blue:95 alpha:1]; self.adjustsImageWhenHighlighted = YES; } return self; } - (void)dealloc { [super dealloc]; } @end Now the problem with the above code is that it does not create buttons that look similar to the buttons created by default in Interface builder. The borders are missing. And I create buttons of the above type by the following code: HopitalButton* hb = [[HopitalButton alloc] init]; hb.button_type = @"call"; hb.frame = CGRectMake(50, 50 + i * 67, 220, 40); [self.scroll_view addSubview:hb]; [hb setTitle:[[[self.office_full_list objectAtIndex:i] objectForKey:@"Staff" ]objectForKey:@"FullName"] forState:UIControlStateNormal]; hb.index = [NSNumber numberWithInt:[self.button_items count]]; [self.button_items insertObject:hb atIndex:[self.button_items count]]; [hb addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; I am not finding a way to set the button type for this custom button. Is there a way i can do it ? Or is there a better way to design the code.

    Read the article

  • detecting double free object, release or not release ...

    - by mongeta
    Hello, If we have this code in our interface .h file: NSString *fieldNameToStoreModel; NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext; DataEntered *dataEntered; In our implementation file .m we must have: - (void)dealloc { [fieldNameToStoreModel release]; [fetchedResultsController release]; [managedObjectContext release]; [dataEntered release]; [super dealloc]; } The 4 objects are assigned from a previous UIViewController, like this: UIViewController *detailViewController; detailViewController = [[CarModelSelectViewController alloc] initWithStyle:UITableViewStylePlain]; ((CarModelSelectViewController *)detailViewController).dataEntered = self.dataEntered; ((CarModelSelectViewController *)detailViewController).managedObjectContext = self.managedObjectContext; ((CarModelSelectViewController *)detailViewController).fieldNameToStoreModel = self.fieldNameToStoreModel; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; The objects that now live in the new UIViewController, are the same as the previous UIViewController, and I can't release them in the new UIViewController ? The problems is that sometimes, my app crashes when I leave the new UIViewController and go to the previous one, not always. Normally the error that I'm getting is a double free object. I've used the malloc_error_break but I'm still not sure wich object is. Sometimes I can go from the previous UIViewController to the next one and come back 4 or 5 times, and the double free object appears. If I don't release any object, all is working and Instruments says that there are no memory leaks ... So, the final question, should I release those objects here or not ? Thanks, m.

    Read the article

  • Implementing the ‘defer’ statement from Go in Objective-C?

    - by zoul
    Hello! Today I read about the defer statement in the Go language: A defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perform various clean-up actions. I thought it would be fun to implement something like this in Objective-C. Do you have some idea how to do it? I thought about dispatch finalizers, autoreleased objects and C++ destructors. Autoreleased objects: @interface Defer : NSObject {} + (id) withCode: (dispatch_block_t) block; @end @implementation Defer - (void) dealloc { block(); [super dealloc]; } @end #define defer(__x) [Defer withCode:^{__x}] - (void) function { defer(NSLog(@"Done")); … } Autoreleased objects seem like the only solution that would last at least to the end of the function, as the other solutions would trigger when the current scope ends. On the other hand they could stay in the memory much longer, which would be asking for trouble. Dispatch finalizers were my first thought, because blocks live on the stack and therefore I could easily make something execute when the stack unrolls. But after a peek in the documentation it doesn’t look like I can attach a simple “destructor” function to a block, can I? C++ destructors are about the same thing, I would create a stack-based object with a block to be executed when the destructor runs. This would have the ugly disadvantage of turning the plain .m files into Objective-C++? I don’t really think about using this stuff in production, I’m just interested in various solutions. Can you come up with something working, without obvious disadvantages? Both scope-based and function-based solutions would be interesting.

    Read the article

  • _resignRootViewController causes app to crash.

    - by RickiG
    [MainViewController _resignRootViewController]: message sent to deallocated instance 0x4ebfe50 This error happens when I try to pop my MainViewController Object from within it self: - (void) switchToTableView { //a method on the MainViewController [self.navigationController popViewControllerAnimated:NO]; [[UIApplication applicationDelegate] switchToTableView]; //convenience method for the app delegate } The debugger stops at the [super dealloc] command in MainViewControllers dealloc method. I do the exact same thing in the TripTableViewController, but here it never crashes. MainViewController and TripTableViewController are handled in my AppDelegate like this: - (void) switchToTableView { TripTableViewController *tripTableViewController = [[TripTableViewController alloc] init]; [[self.navigationController navigationBar] setHidden:NO]; [self.navigationController pushViewController:tripTableViewController animated:NO]; [tripTableViewController release]; } - (void) switchToScrollView { MainViewController *scrollView = [[MainViewController alloc] init]; [[self.navigationController navigationBar] setHidden:YES]; [self.navigationController pushViewController:scrollView animated:NO]; [scrollView release]; } I am trying to achieve that when the user goes from TripTableViewController to MainViewController; TripTableViewController is released/popped and visa versa for the MainViewController. I do not wish for the navigationController to make the decision about when to pop/cache/release them, this is why I try to do it from within it self. I have not been able to find the _resignRootViewController mentioned anywhere. My guess is that it is a delegate message sent by a ViewController that resigns as rootViewController for a navigationController and that somehow it is called twice, once before MainViewCOntroller is released/popped and somehow again afterwards. Have any one else seen this error message before? Google and the Apple Docs does not mention it? How can I debug such an error? Hope someone can guide me in the right direction on this one, Thanks:)

    Read the article

  • Why I got some memory problems?

    - by Tattat
    I got this error from XCode: objc[8422]: FREED(id): message release sent to freed object=0x3b120c0 I googled and find that is related to the memory. But I don't know which line of code I go wrong, any ideas? @implementation MyAppDelegate @synthesize window; @synthesize viewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:viewController.view]; [window makeKeyAndVisible]; [self changeScene:[MainGameMenuScene class]]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } - (void) changeScene: (Class) scene { BOOL animateTransition = true; if(animateTransition){ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; //does nothing without this line. } if( viewController.view != nil ) { [viewController.view removeFromSuperview]; //remove view from window's subviews. [viewController.view release]; //release gamestate } viewController.view = [[scene alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) andManager:self]; //now set our view as visible [window addSubview:viewController.view]; [window makeKeyAndVisible]; if(animateTransition){ [UIView commitAnimations]; } }

    Read the article

  • SubViewTwoController undeclared (first use in this function) (obj-c)

    - by benny
    Ahoy hoy everyone :) Here is a list of links. You will need it when reading the post. I am a newbie to Objective-C and try to learn it for iPhone-App-Development. I used the tutorial linked in the link list to create a standard app with a simple basic Navigation. This app contains a "RootView" that is displayed at startup. The startup screen itself contains three elements wich all link to SubViewOne. I have got it to work this far. So what i want to change is to make the second element link to SubViewTwo. When i "Build and Go" it, i get the following errors: RootViewController.m: SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init]; // SubViewTwoController undeclared (first use in this function) and in SubViewTwoController.m [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview no superclass declared in @interface for ´SubViewTwoController´ and the same thing after - (void)dealloc { [super dealloc]; I think you will also need the header files, so here they are! RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UITableViewController { IBOutlet NSMutableArray *views; } @property (nonatomic, retain) IBOutlet NSMutableArray *views; @end SubViewOneController.h #import <UIKit/UIKit.h> @interface SubViewOneController : UIViewController { IBOutlet UILabel *label; IBOutlet UIButton *button; } @property (retain,nonatomic) IBOutlet UILabel *label; @property (retain,nonatomic) IBOutlet UIButton *button; - (IBAction) OnButtonClick:(id) sender; @end and SubViewTwoController.h #import <UIKit/UIKit.h> @interface SubViewTwo : UIViewController { IBOutlet NSMutableArray *views; } @end I would be really great if you would leave your ideas with a short explanation. Thanks a lot in advance! benny

    Read the article

  • Calling a method on an unitialized object (null pointer)

    - by Florin
    What is the normal behavior in Objective-C if you call a method on an object (pointer) that is nil (maybe because someone forgot to initialize it)? Shouldn't it generate some kind of an error (segmentation fault, null pointer exception...)? If this is normal behavior, is there a way of changing this behavior (by configuring the compiler) so that the program raises some kind of error / exception at runtime? To make it more clear what I am talking about, here's an example. Having this class: @interface Person : NSObject { NSString *name; } @property (nonatomic, retain) NSString *name; - (void)sayHi; @end with this implementation: @implementation Person @synthesize name; - (void)dealloc { [name release]; [super dealloc]; } - (void)sayHi { NSLog(@"Hello"); NSLog(@"My name is %@.", name); } @end Somewhere in the program I do this: Person *person = nil; //person = [[Person alloc] init]; // let's say I comment this line person.name = @"Mike"; // shouldn't I get an error here? [person sayHi]; // and here [person release]; // and here

    Read the article

  • Adding a custom subview (created in a xib) to a view controller's view - What am I doing wrong

    - by Fran
    I've created a view in a xib (with an activity indicator, a progress view and a label). Then I've created .h/.m files: #import <UIKit/UIKit.h> @interface MyCustomView : UIView { IBOutlet UIActivityIndicatorView *actIndicator; IBOutlet UIProgressView *progressBar; IBOutlet UILabel *statusMsg; } @end #import "MyCustomView.h" @implementation MyCustomView - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Initialization code } return self; } - (void)dealloc { [super dealloc]; } @end In IB, I set the file's owner and view identity to MyCustomView and connect the IBOutlet to the File's owner In MyViewController.m, I've: - (void)viewDidLoad { [super viewDidLoad]; UIView *subView = [[MyCustomView alloc] initWithFrame:myTableView.frame]; [subView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]]; [myTableView addSubview:subView]; [subView release]; } When I run the app, the view is added, but I can't see the label, the progress bar and the activity indicator. What am I doing wrong?

    Read the article

  • AVAudioPlayer not unloading cached memory after each new allocation

    - by Rob
    I am seeing in Instruments that when I play a sound via the standard "AddMusic" example method that Apple provides, it allocates 32kb of memory via the prepareToPlay call (which references the AudioToolBox framework's Cache_DataSource::ReadBytes function) each time a new player is allocated (i.e. each time a different sound is played). However, that cached data never gets released. This obviously poses a huge problem if it doesn't get released and you have a lot of sound files to play, since it tends to keep allocating memory and eventually crashes if you have enough unique sound files (which I unfortunately do). Have any of you run across this or what am I doing wrong in my code? I've had this issue for a while now and it's really bugging me since my code is verbatim of what Apple's is (I think). How I call the function: - (void)playOnce:(NSString *)aSound { // Gets the file system path to the sound to play. NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"]; // Converts the sound's file path to an NSURL object NSURL *soundURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; self.soundFileURL = soundURL; [soundURL release]; AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error:nil]; self.theAudio = newAudio; // automatically retain audio and dealloc old file if new m4a file is loaded [newAudio release]; // release the audio safely // this is where the prior cached data never gets released [theAudio prepareToPlay]; // set it up and play [theAudio setNumberOfLoops:0]; [theAudio setVolume: volumeLevel]; [theAudio setDelegate: self]; [theAudio play]; } and then theAudio gets released in the dealloc method of course.

    Read the article

  • Custom back button click event on pushed view controller

    - by TechFusion
    Hello, I have pushed view controller and load WebView and Custom rectangular rounded button on right down left corner into view using programmatic way. -(void)loadView { CGRect frame = CGRectMake(0.0, 0.0, 480, 320); WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease]; WebView.backgroundColor = [UIColor whiteColor]; WebView.scalesPageToFit = YES; WebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin); WebView.autoresizesSubviews = YES; WebView.exclusiveTouch = YES; WebView.clearsContextBeforeDrawing = YES; self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; self.roundedButtonType.frame = CGRectMake(416.0, 270.0, 44, 19); [self.roundedButtonType setTitle:@"Back" forState:UIControlStateNormal]; self.roundedButtonType.backgroundColor = [UIColor grayColor]; [self.roundedButtonType addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside]; self.view = WebView; [self.view addSubview: self.roundedButtonType ]; [WebView release]; } This is action that I have added as back button of navigation. -(void)back:(id)sender{ [self.navigationController popViewControllerAnimated:YES]; } -(void)viewDidUnload{ self.WebView = nil; self.roundedButtonType = nil; } -(void)dealloc{ [roundedButtonType release]; [super dealloc]; } Here, When Back button click then it is showing previous view but application got stuck in that view and GDB shows Program received signal :EXC_BAD_ACCESS message. how resolve this issue? Thanks,

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >