Search Results

Search found 779 results on 32 pages for 'uiimage'.

Page 13/32 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • imageWithCGImage and memory

    - by Adam Ernst
    If I use [UIImage imageWithCGImage:], passing in a CGImageRef, do I then release the CGImageRef or does UIImage take care of this itself when it is deallocated? The documentation isn't entirely clear. It says "This method does not cache the image object." Originally I called CGImageRelease on the CGImageRef after passing it to imageWithCGImage:, but that caused a malloc_error_break warning in the Simulator claiming a double-free was occurring.

    Read the article

  • Is garbage collection supported for iPhone applications?

    - by Mustafa
    Does the iPhone support garbage collection? If it does, then what are the alternate ways to perform the operations that are performaed using +alloc and -init combination: NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData]; UIImage *originalImage = [[UIImage alloc] initWithData:data]; detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailView bundle:[NSBundle mainBundle]] autorelease]; ... and other commands. Thank you in advance for any help or direction that you can provide.

    Read the article

  • Iphone UIButton not working in nested UIViews

    - by Charles Peterson
    This is so damn simple im sure! Im missing something and im exhausted from trying to fix it. hopefully someone can help. The Button in CharacterView.m works but the button nested down in CharacterMale.m does not. I'm not using IB everything is done progmatically. What would cause one button to work and other not? ///////////////////////////////////////////////////////////////////////////////// CharacterController.m ///////////////////////////////////////////////////////////////////////////////// #import "CharacterController.h" #import "CharacterView.h" @implementation CharacterController - (id)init { NSLog(@"CharacterController init"); self = [ super init ]; if (self != nil) { } return self; } - (void)loadView { [ super loadView ]; characterView = [ [ CharacterView alloc ] init]; self.view = characterView; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { [super dealloc]; } @end ///////////////////////////////////////////////////////////////////////////////// CharacterView.m ///////////////////////////////////////////////////////////////////////////////// #import "CharacterView.h" #import "CharacterMale.h" @implementation CharacterView - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { characterMale = [ [ CharacterMale alloc ] init]; [self addSubview: characterMale]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, 200, 200, 100); [button setImage:[UIImage imageNamed:@"btnCharSelect.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(ApplyImage:) forControlEvents:UIControlEventTouchUpInside]; [ self addSubview: button ]; } return self; } - (void)drawRect:(CGRect)rect { } -(void)ApplyImage:(id)sender { NSLog(@"CharacterView button works"); } - (void)dealloc { [super dealloc]; } @end ///////////////////////////////////////////////////////////////////////////////// CharacterMale.m ///////////////////////////////////////////////////////////////////////////////// #import "CharacterMale.h" #import "CharacterController.h" @implementation CharacterMale - (id)init { self = [ super init]; if (self != nil) { UIImage *image = [UIImage imageNamed:@"charMale.png"]; imageView = [[ UIImageView alloc] initWithImage:image]; [image release]; [ self addSubview: imageView ]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0, 0, 200, 100); [button setImage:[UIImage imageNamed:@"btnCharSelect.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(ApplyImage:) forControlEvents:UIControlEventTouchUpInside]; [ self addSubview: button ]; } return self; } -(void)ApplyImage:(id)sender { NSLog(@"CharacterMal button works"); } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Didn't load images when I test version on Iphone

    - by Igor
    I use images from resources like that: UIImage *image = [ UIImage imageNamed:@"example.jpg" ]; UIImageView *imageView = [ [UIImageView alloc] initWithImage:image ]; When I test it on semulator it's works. But on Iphone no. Also image with size about 10Kb loaded, with size about 100Kb no. Whats wrong?

    Read the article

  • UINavigationBar Background Image Problem

    - by tobi
    i have set my navigationbar background with this code in my App delegate: @implementation UINavigationBar (UINavigationBarCategory) - (void)drawRect:(CGRect)rect { UIImage *backgroundImage = [UIImage imageNamed: @"Nav-rightpane.png"]; CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), backgroundImage.CGImage); } @end This works perfect but now i must change the background to the default at UIPopoverController. Any idea for this? Thanks

    Read the article

  • How to remove subviews to release more memory

    - by Tankista
    I have UIScrollView with number of subviews. Each subview is custom UIButton with UIImage. When I load more and more subviews, more and more memory is used. But I remove invisible subviews by removeFromSuperView method. Subviews are removed and stay invisible, but Im afraid that no memory is released. UIImage is image downloaded from internet. Thanx for help.

    Read the article

  • Why I can't draw in a loop? (Using UIView in iPhone)

    - by Tattat
    I can draw many things using this : NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"dummy2.png" ofType:nil]; UIImage *img = [UIImage imageWithContentsOfFile:imagePath]; image = CGImageRetain(img.CGImage); CGRect imageRect; double x = 0; double y = 0; for (int k=0; k<someValue; k++) { x += k; y += k; imageRect.origin = CGPointMake(x, y); imageRect.size = CGSizeMake(25, 25); CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image); } } CGImageRelease(img.CGImage); So, it works, so, I put it into a command object's execute method. Then, I want to do similar thing, but this time, my execute method only do this: NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"dummy2.png" ofType:nil]; UIImage *img = [UIImage imageWithContentsOfFile:imagePath]; image = CGImageRetain(img.CGImage); CGRect imageRect; double x = inComingX; double y = inComingY; imageRect.origin = CGPointMake(x, y); imageRect.size = CGSizeMake(25, 25); CGContextDrawImage(UIGraphicsGetCurrentContext(), imageRect, image); CGImageRelease(img.CGImage); This time, this is also a Command, and it is the execute method. But I take the for loop away. I will have another method that pass the inComingX , and inComingY into my Command object. My Drawing method is simply execute the Cmd that passed in my drawingEngine: -(void)drawInContext:(CGContextRef)context { [self.cmdToBeExecuted execute]; } I also have the assign method to assign the command,: -(void)assignCmd:(Command* )cmd{ self.cmdToBeExecuted = cmd; } And this is the way I called the drawingEngine for(int k=0; k<5; k++){ [self.drawingEngine assignCmd:[DrawingCmd setDrawingInformation:(10*k):0:@"dummy.png"]]; [self.drawingEngine setNeedsDisplay]; } It can draw, but the sad thing is it only draw the last one. Why? and how to fix it? I can draw all the things in my First code, but after I take the loop outside, and use the loop in last code, it just only draw the last one. Plz help

    Read the article

  • Re-Add tabBarController's view into window and the device is in landscape mode

    - by user285553
    Hello, I have an app that is a tabBarController based app. I have 4 tabs on it and one of these is for logging in/out in my app. The main ideea is that when I logout, I release the tabBarController (this will release the all 4 view controllers too - I have done this becuse I want to refersh all the views after logging out to look just like the first time).After this, I alloc it again and add the view controllers aagin,set the tabBarItem's titles,etc.This work ok. The problem is when I am in landscape mode;my logout view is painted to fit the landscape area,but after disconnect(now I releasse and alloc again the tabbarController) the view is painted in portrait mode but my device is in lanscape. After disconnected, I call the releaseOldTabView and the createNewTabView.After this tabBarController is in portrait insead of landscape. -(void)releaseOldTabView:(BOOL)tabViewEnabled{ if(tabViewEnabled){ [tabBarController.view removeFromSuperview]; [tabBarController release]; } } -(void)createNewTabView{ tabBarController = [[UITabBarController alloc] init]; NSMutableArray *oneArray = [[NSMutableArray alloc] init]; tabBarController.delegate = self; LoginViewController *login= [[LoginViewController2 alloc] initWithNibName:@"LoginViewController" bundle:nil]; SecondViewController *secondController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; ThirdViewController *thirdController = [[ThirdViewController alloc] init]; FourthViewController *fourthController = [[FourthViewController alloc] init]; login.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Login" image:[UIImage imageNamed:@"connect.png"] tag:0]; secondController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"TabBar2" image:[UIImage imageNamed:@"tabBar2.png"] tag:1]; thirdController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"TabBar3" image:[UIImage imageNamed:@"tabBar3.png"] tag:2]; fourthController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"TabBar4" image:[UIImage imageNamed:@"tabBar4.png"] tag:3]; [oneArray addObject:login]; [oneArray addObject:secondController]; [oneArray addObject:thirdController]; [oneArray addObject:fourthController]; [tabBarController setViewControllers:oneArray]; //[tabBarController.view convertRect:tabBarController.view.frame toView:window]; [window addSubview:tabBarController.view]; [oneArray release]; [login release]; [secondController release]; [thirdController release]; [fourthController release]; } After calling this method, the tabbar view is in portrait,but statusBar(the top bar which says the carrier name) is painted normally(landscape). I also tried the [tabBarController.view convertRect:tabBarController.view.frame toView:window]; but without any succes. Can anyone give a hand of help? Thanks in advance, Alex.

    Read the article

  • +(void) initialize in objecive c class static variables construstor

    - by sugar
    I found some sample code from here. static UIImage *backgroundImageDepressed; /** * */ @implementation DecimalPointButton + (void) initialize { backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain]; } is it something like this - +(void) initialize method initialize static variables of a class ( interface ) in objective c ? I have never seen this before. Please need your guidance on it. Thanks in advance for sharing your great knowledge. Sagar

    Read the article

  • Changing RGB color image to Grayscale image using Objective C

    - by user567167
    I was developing a application that changes color image to gray image. However, some how the picture comes out wrong. I dont know what is wrong with the code. maybe the parameter that i put in is wrong please help. UIImage *c = [UIImage imageNamed:@"downRed.png"]; CGImageRef cRef = CGImageRetain(c.CGImage); NSData* pixelData = (NSData*) CGDataProviderCopyData(CGImageGetDataProvider(cRef)); size_t w = CGImageGetWidth(cRef); size_t h = CGImageGetHeight(cRef); unsigned char* pixelBytes = (unsigned char *)[pixelData bytes]; unsigned char* greyPixelData = (unsigned char*) malloc(w*h); for (int y = 0; y < h; y++) { for(int x = 0; x < w; x++){ int iter = 4*(w*y+x); int red = pixe lBytes[iter]; int green = pixelBytes[iter+1]; int blue = pixelBytes[iter+2]; greyPixelData[w*y+x] = (unsigned char)(red*0.3 + green*0.59+ blue*0.11); int value = greyPixelData[w*y+x]; } } CFDataRef imgData = CFDataCreate(NULL, greyPixelData, w*h); CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData(imgData); size_t width = CGImageGetWidth(cRef); size_t height = CGImageGetHeight(cRef); size_t bitsPerComponent = 8; size_t bitsPerPixel = 8; size_t bytesPerRow = CGImageGetWidth(cRef); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGBitmapInfo info = kCGImageAlphaNone; CGFloat *decode = NULL; BOOL shouldInteroplate = NO; CGColorRenderingIntent intent = kCGRenderingIntentDefault; CGDataProviderRelease(imgDataProvider); CGImageRef throughCGImage = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, info, imgDataProvider, decode, shouldInteroplate, intent); UIImage* newImage = [UIImage imageWithCGImage:throughCGImage]; CGImageRelease(throughCGImage); newImageView.image = newImage;

    Read the article

  • Question related to photogallery

    - by user217572
    I'm saving my image to photo gallary , but I want to fetch this image on click of UIButton and want to show it on the UIImageview or UIview.My code for saving image on photo gallery is as under:- I don't want to use UIImagePickerViewController any where in my programme UIImage *image = [UIImage imageNamed:@"flower.png"]; UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

    Read the article

  • Rendering problem with UITableview

    - by Spider-Paddy
    I have a very strange problem with a UITableview within a navigation controller on the iPhone simulator. Of the cells displayed, only some are correctly rendered. They are all supposed to look the same but the majority are missing the accessory I've set, scrolling the view changes which cell has the accessory so I suspect it's some sort of cell caching happening, although the contents are correct for each cell. I also set an image as the background and that was also only displaying sporadically but I fixed that by changing cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]]; (which also only rendered a random cell with the background) to cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]]; I now need to fix the problem with the accessory only showing on a random cell. I tried moving the code from cellForRowAtIndex to willDisplayCell but it made no difference. I put in a log command to confirm that it is running through each frame. Basically it's a table view (UITableViewCellStyleSubtitle) that gets its info from a server & is then updated by a delegate method calling reload. Code is: -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"%@", [NSString stringWithFormat:@"Setting colours for cell %i", indexPath.row]); // Set cell background // cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]]; cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; // detailTableViewAccessory is a view containing an imageview in this view's nib // i.e. nib <- view <- imageview <- image cell.accessoryView = detailTableViewAccessory; } // Called by data fetching object when done -(void)listDataTransferComplete:(ArticleListParser *)articleListParserObject { NSLog(@"Data parsed, reloading detail table"); self.currentTotalResultPages = (((articleListParserObject.currentArticleCount - 1) / 10) + 1); self.detailTableDataSource = [articleListParserObject.returnedArray copy]; // make a local copy of the returned array // Render table again with returned array data (neither of these 2 fixed it) [self.detailTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; // [self.detailTableView reloadData]; // Re-enable necessary buttons (including table cells) letUserSelectRow = TRUE; [btnByName setEnabled:TRUE]; [btnByPrice setEnabled:TRUE]; // Remove please wait message NSLog(@"Removing please wait view"); [pleaseWaitViewControllerObject.view removeFromSuperview]; } I only included code that I thought was relevant, can supply more if needed. I can't test it on an iPhone yet so I don't know if it's maybe just a simulator anomaly or a bug in my code. I've always gotten good feedback from questions, any ideas?

    Read the article

  • Objective-C: iPad Crash When Screen Shot Button Clicked

    - by SeongHo
    OK, i am making a Coloring app and it has a "Save" button that will take the screen shot of the view where the drawing is. I have 6 images to color. In the intro page there 6 buttons, each will link you to a particular coloring page. All are working well including the "Save" button except for one. All coloring views has the same contents and functions but in one image, it crashes the iPad whenever i clicked the "Save" button. Here's some of my codes: On Button Click: [self saveScreenshotToPhotosAlbum]; camFlash = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; [camFlash setBackgroundColor:[UIColor whiteColor]]; [camFlash setAlpha:0.0]; [cbHolder addSubview:camFlash]; [cbHolder bringSubviewToFront:camFlash]; [UIView beginAnimations:@"Flash-On" context:NULL]; [UIView setAnimationDuration:0.2]; [UIView setAnimationRepeatAutoreverses:NO]; [camFlash setAlpha:1.0]; [UIView commitAnimations]; NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"flash" ofType:@"wav"]; AVAudioPlayer *flashSFX = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL]; flashSFX.volume = 0.5; flashSFX.numberOfLoops = 0; self->camFlashSFX = flashSFX; if ([flashSFX currentTime] != 0) [flashSFX setCurrentTime:0]; [flashSFX play]; [self performSelector:@selector(removeFlash) withObject:nil afterDelay:0.2]; Remove Flash: - (void) removeFlash { [camFlash removeFromSuperview]; } For the screenshot: - (UIImage*)captureView { UIGraphicsBeginImageContext(CGSizeMake(1024, 768)); CGContextRef context = UIGraphicsGetCurrentContext(); [cbHolder.layer renderInContext:context]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } - (void)saveScreenshotToPhotosAlbum { UIImageWriteToSavedPhotosAlbum([self captureView], nil, nil, nil); } This one is for the button that will show the coloring page: uc4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tpUncolored1.png"]]; [uc4 setUserInteractionEnabled:YES]; [uc4 setFrame:CGRectMake(0, 0, 1024, 768)]; [cbHolder addSubview:uc4]; clrd4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tpColored1.png"]]; [clrd4 setUserInteractionEnabled:YES]; [clrd4 setFrame:CGRectMake(0, 0, 1024, 768)]; [cbHolder addSubview:clrd4]; [UIView beginAnimations:@"fabe-out" context:NULL]; [UIView setAnimationDuration:1.5]; [clrd4 setAlpha:0.0]; [UIView commitAnimations]; [self performSelector:@selector(cb4) withObject:nil afterDelay:1.5];

    Read the article

  • Why does this crash: stringByAppendingFormat

    - by Emil
    Hey. My code crashes at this function (at the stringByAppendingFormat: with error objc_msgSend() selector name: stringByAppendingFormat). This is that line: // imagesPath = ...iPhone Simulator/4.0/Applications/NUMBERS/Documents/images UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingFormat:@"/%d.png", [[self.postsArrayID objectAtIndex:row] intValue]]]; Could it have something to do with the retaining of objects? Thanks :)

    Read the article

  • how can i show ccessarychecked cell values in alertbox

    - by adnan
    i have created uitableview and cell in uitableview are accessarychecked . i have implemented an action named -(IBAction) checkBoxClicked . what i need is that i wanted to show accessarychecked cell values in alertbox when i click on button this is the code which i have written #import "ViewController.h" @implementation ViewController @synthesize cell; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell= [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [myarray objectAtIndex:indexPath.row]; /* NSString *imagefile = [[NSBundle mainBundle] pathForResource:@"cellimage" ofType:@"png"]; UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imagefile]; cell.imageView.image = ui;*/ NSString *check = [[NSBundle mainBundle] pathForResource:@"checkbox_not_ticked" ofType:@"png"]; UIImage *bi = [[UIImage alloc] initWithContentsOfFile:check]; cell.imageView.image = bi; cell.accessoryType = UITableViewCellAccessoryNone; return cell; [cell release]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } } -(IBAction) checkBoxClicked { NSArray *array = [[NSArray alloc] initWithArray:[myarray objectAtIndex:cell.accessoryType]:UITableViewCellAccessoryCheckmark]; if (array.cell.accessoryType == UITableViewCellAccessoryCheckmark) { UIAlertView *msg = [[ UIAlertView alloc] initWithTitle:@"selected items are given: " message:array delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ]; [msg show ]; [msg release]; [myarray release]; } } //-(IBAction)checkBoxClicked{} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { myarray = [[NSArray alloc] initWithObjects:@"mondey",@"tuesday", @"wednesday",@"thursday",@"friday",@"saturday",@"sundey", nil]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [myarray release]; [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end

    Read the article

  • Monotouch UITableView image "flashing" while background requests are fetched

    - by Themos Piperakis
    I am in need of some help from you guys. I have a Monotouch UITableView which contains some web images. I have implemented a Task to fetch them asynchronously so the UI is responsive, an even added some animations to fade them in when they are fetched from the web. My problems start when the user scrolls down very fast down the UITableView, so since the cells are resusable, several background tasks are queued for images. When he is at the bottom of the list, he might see the thumbnail displaying an image for another cell, then another, then another, then another, as the tasks are completed and each image replaces the other one. I am in need of some sort of checking whether the currently displayed cell corresponds to the correct image url, but not sure how to do that. Here is the code for my TableSource class. using System; using MonoTouch.UIKit; using MonoTouch.Foundation; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Diagnostics; { public class ListDelegate:UITableViewDelegate { private UINavigationController nav; public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath) { return 128; } public override void RowSelected (UITableView tableView, NSIndexPath indexPath) { DealViewController c = new DealViewController(((ListDataSource)tableView.DataSource).deals[indexPath.Row].Id,nav); nav.PushViewController(c,true); tableView.DeselectRow(indexPath,true); } public ListDelegate(UINavigationController nav) { this.nav = nav; } } public class ListDataSource:UITableViewDataSource { bool toggle=true; Dictionary<string,UIImage> images = new Dictionary<string, UIImage>(); public List<MyDeal> deals = new List<MyDeal>(); Dictionary<int,ListCellViewController> controllers = new Dictionary<int, ListCellViewController>(); public ListDataSource(List<MyDeal> deals) { this.deals = deals; } public override int RowsInSection (UITableView tableview, int section) { return deals.Count; } public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell("cell"); ListCellViewController cellController = null; if (cell == null || !controllers.ContainsKey(cell.Tag)) { cellController = new ListCellViewController(); NSBundle.MainBundle.LoadNib("ListCellViewController", cellController, null); cell = cellController.Cell; cell.Tag = Environment.TickCount; controllers.Add(cell.Tag, cellController); } else { cellController = controllers[cell.Tag]; } if (toggle) { cell.BackgroundView = new UIImageView(UIImage.FromFile("images/bg1.jpg")); } else { cell.BackgroundView = new UIImageView(UIImage.FromFile("images/bg2.jpg")); } toggle = !toggle; MyDeal d = deals[indexPath.Row]; cellController.SetValues(d.Title,d.Price,d.Value,d.DiscountPercent); GetImage(cellController.Thumbnail,d.Thumbnail); return cell; } private void GetImage(UIImageView img, string url) { img.Alpha = 0; if (url != string.Empty) { if (images.ContainsKey(url)) { img.Image = images[url]; img.Alpha = 1; } else { var context = TaskScheduler.FromCurrentSynchronizationContext (); Task.Factory.StartNew (() => { NSData imageData = NSData.FromUrl(new NSUrl(url)); var uimg = UIImage.LoadFromData(imageData); images.Add(url,uimg); return uimg; }).ContinueWith (t => { InvokeOnMainThread(()=>{ img.Image = t.Result; RefreshImage(img); }); }, context); } } } private void RefreshImage(UIImageView img) { UIView.BeginAnimations("imageThumbnailTransitionIn"); UIView.SetAnimationDuration(0.5f); img.Alpha = 1.0f; UIView.CommitAnimations(); } } } Here is the ListCellViewController, that contains a custom cell using System; using System.Collections.Generic; using System.Linq; using MonoTouch.Foundation; using MonoTouch.UIKit; { public partial class ListCellViewController : UIViewController { #region Constructors // The IntPtr and initWithCoder constructors are required for items that need // to be able to be created from a xib rather than from managed code public ListCellViewController (IntPtr handle) : base(handle) { Initialize (); } [Export("initWithCoder:")] public ListCellViewController (NSCoder coder) : base(coder) { Initialize (); } public ListCellViewController () : base("ListCellViewController", null) { Initialize (); } void Initialize () { } public UIImageView Thumbnail { get{return thumbnailView;} } public UITableViewCell Cell { get {return cell;} } public void SetValues(string title,decimal price,decimal valuex,decimal discount,int purchases) { } #endregion } } All help is greatly appreciated

    Read the article

  • UIBarButtonItem with custom image and no border

    - by mongeta
    Hello, I want to create a UIBarButtonItem with a custom image, but I don't want the border that iPhone adds, as my Image has a special border. It's the same as the back button but a forward button. This App is for an inHouse project, so I don't care if Apple reject or approves it or likes it :-) If I use the initWithCustomView:v property of the UIBarButtonItem, I can do it: UIImage *image = [UIImage imageNamed:@"right.png"]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal]; [button setBackgroundImage: [[UIImage imageNamed: @"right_clicked.png"] stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateHighlighted]; button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height); [button addTarget:self action:@selector(AcceptData) forControlEvents:UIControlEventTouchUpInside]; UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ]; [v addSubview:button]; UIBarButtonItem *forward = [[UIBarButtonItem alloc] initWithCustomView:v]; self.navigationItem.rightBarButtonItem= forward; [v release]; [image release]; This works, but if I have to repeat this process in 10 views, this is not DRY. I suppose I have to subclass, but what ? NSView ? UIBarButtonItem ? thanks, regards,

    Read the article

  • UIImagePickerController weirdness ...

    - by John Michael Zorko
    Hello, all ... UIImagePickerController is easy to use, but i'm all of a sudden finding it exasperating when I didn't find it so before. What's happening is that sometimes the imagePickerController:didFinishPickingImage:editingInfo delegate method does not seem to work -- the image will not show in the UIImageView even after the assignment was made. Sometimes it will, sometimes not, and furthermore, every single bit of example code i've tried (from the web, from the "Beginning iPhone 3 Development" book, etc.) exhibits the same problem. I'm at a loss as to why, and the problem happens on both my iPhone 3G as well as my 3GS, so I doubt that it's a hardware issue. These devices are running OS 3.1.2. The view controller is loaded from a xib file that contains one button and the UIImageView. I'd really like someone to tell me what stupid thing i'm obviously doing wrong :-) Here is the code -- i've tried to make the smallest app I could that exhibits the problem: #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface imagepickerViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> { IBOutlet UIButton *button; IBOutlet UIImageView *imageView; } @property (nonatomic, retain) UIImageView *imageView; - (IBAction)takepic; - (void)usePic:(UIImage *)pic; @end #import "imagepickerViewController.h" @implementation imagepickerViewController @synthesize imageView; - (IBAction)takepic { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; [self presentModalViewController:picker animated:YES]; [picker release]; } } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)info { [self usePic:image]; [picker dismissModalViewControllerAnimated:YES]; // after this method returns, the UIImageView should show the image -- yet very often it does not ... } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissModalViewControllerAnimated:YES]; } - (void)usePic:(UIImage *)picture { imageView.image = picture; } @end

    Read the article

  • memory warning, generating UIImagefrom pdf files in objective-c

    - by favo
    When converting PDF Pages into UIImages I receive memory warnings all the time. It seems there is either some leak or something else that eats my memory. Using instruments didn't give me any helpful details. I'm using the following function to generate images from a pdf file: - (UIImage*)pdfImage:(NSString*)pdfFilename page:(int)page { CFURLRef pdfURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)pdfFilename, kCFURLPOSIXPathStyle, false); CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); CFRelease(pdfURL); CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfRef, page); CGRect pdfPageSize = CGPDFPageGetBoxRect(pdfPage, kCGPDFBleedBox); float pdfScale; if ( pdfPageSize.size.width < pdfPageSize.size.height ) { pdfScale = PDF_MIN_SIZE / pdfPageSize.size.width; } else { pdfScale = PDF_MIN_SIZE / pdfPageSize.size.height; } CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(NULL, pdfPageSize.size.width*pdfScale, pdfPageSize.size.height*pdfScale, 8, (int)pdfPageSize.size.width*pdfScale * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); CGColorSpaceRelease(colorSpace); // CGContextClipToRect(context, pdfPageView.frame); // CGPDFPageRetain(pdfPage); CGAffineTransform transform = aspectFit(CGPDFPageGetBoxRect(pdfPage, kCGPDFBleedBox), CGContextGetClipBoundingBox(context)); CGContextConcatCTM(context, transform); CGContextDrawPDFPage(context, pdfPage); // CGPDFPageRelease (pdfPage); CGImageRef image = CGBitmapContextCreateImage(context); CGContextRelease(context); UIImage *finalImage = [UIImage imageWithCGImage:image]; CGImageRelease(image); CGPDFDocumentRelease(pdfRef); return finalImage; } I am releasing the document and everything else, so where could be the problem? Thanks for your help!

    Read the article

  • Custom UITableViewCell won't redraw on setNeedsDisplay

    - by Andrew Portner
    I created a custom UITableViewCell class with a UIButton, a UIImage, and two UILabels. The button and the image are overlayed on top of each other, and only one is displayed at a time. The expected behavior is you touch on the button, the button disappears, and it displays the image. The UITableViewCells are set to be reused. Here's my code: Constructor: - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { unheartButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; unheartButton.backgroundColor = [UIColor clearColor]; unheartButton.frame = CGRectMake(10, 13, 20, 18); [unheartButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [unheartButton setBackgroundImage:[UIImage imageNamed:@"redheart.png"] forState:UIControlStateNormal]; imageView = [[UIImageView alloc] init]; imageView.frame = CGRectMake(12, 13, 16, 16); NSMutableArray *array = [[NSMutableArray alloc] init]; for (int ndx = 1; ndx < 13; ndx++) { [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"icon-loading-%d (dragged).tiff", ndx]]]; } imageView.animationImages = array; imageView.animationDuration = 1; imageView.hidden = YES; [array release]; [self.contentView addSubview:imageView]; [self.contentView addSubview:unheartButton]; return self; } } Button click: - (IBAction) onButtonClick: (id) sender { unheartButton.hidden = YES; imageView.hidden = NO; [imageView startAnimating]; [self setNeedsDisplay]; [self.contentView setNeedsDisplay]; [self.unheartButton setNeedsDisplay]; [self.imageView setNeedsDisplay]; } I'm calling setNeedsDisplay on everything, but nothing seems to happen. If I scroll off the screen and back up, the button is hidden and now the loading icon is shown, but this only happens after a scroll. I'm not sure what I need to do to get the cell to repaint.

    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

  • iPhone - is it IMPOSSIBLE to grab the contents of a CALayers composition?

    - by Mike
    I have a CALayer transformed in 3D on a offscreen UIView (much larger than 320x480). How do I dump what is seen on this UIView to a UIImage? NOTE: I Have edited the question to include this code... This is how I create the layer... CGRect area = CGRectMake (0,0,400,600]; vista3D = [[UIView alloc] initWithFrame:area ]; [self.view addSubview:vista3D]; [vista3D release]; transformed = [CALayer layer]; transformed.frame = area; [vista3D.layer addSublayer:transformed]; CALayer *imageLayer = [CALayer layer]; imageLayer.doubleSided = YES; imageLayer.frame = area; imageLayer.transform = CATransform3DMakeRotation(40 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f); imageLayer.contents = (id)myRawImage.CGImage; [transformed addSublayer:imageLayer]; // Add a perspective effect CATransform3D initialTransform = transformed.sublayerTransform; initialTransform.m34 = 1.0 / -500; transformed.sublayerTransform = initialTransform; // now the layer is in perspective // my next step is to "flatten" the composition into a UIImage UIImage *thisIsTheResult = some magic command thanks for any help! EDIT 1: I have tried jessecurry solution but it gives me a flat layer without any perspective. EDIT 2: I discovered a partial solution for this that works, but this solution gives me an image the size of the screen and I was looking for obtaining a higher resolution version, rendering off screen.

    Read the article

  • How can i attached iphone image through MFMailComposerView in iphone

    - by Pugal Devan
    Hi, I am new to iphone development. I have created a button in the view. On clicking the button it loads the photolibrary from the Iphone. Now i want to attached the those selected image through mail. I donno how can i attached the image in MFMailComposerView. How can i achieve this, Here my code is, -(IBAction) Pictures:(id)sender { self.imgpicker = [[UIImagePickerController alloc] init]; self.imgpicker.delegate = self; self.imgpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:self.imgpicker animated:YES]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img1 editingInfo:(NSDictionary *)editInfo { [[picker parentViewController] dismissModalViewControllerAnimated:NO]; UIView *view = [[UIView alloc] init]; (This view for displaying the images) **imageview** = [[UIImageView alloc] initWithImage:img1]; [imageview setFrame:CGRectMake(0, 0, 320, 420)]; [self.view addSubview:imageview]; [view release]; UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithTitle:@"Email" style:UIBarButtonItemStyleBordered target:self action:@selector(rightbutton)]; self.navigationItem.rightBarButtonItem = rightbutton; [rightbutton release]; } -(void) rightbutton { ***[self emailImage:(UIImage *)image]***;(I donno how to pass the image instance to mail view) } - (void)emailImage:(UIImage *)image { picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; NSData *data = UIImagePNGRepresentation(image); [picker addAttachmentData:data mimeType:@"image/png" fileName:@"iPod Library Image"]; [self presentModalViewController:picker animated:YES]; [picker release]; } Plese help me out. Thanks.

    Read the article

  • Objecive C Error, Message sent to deallocated object

    - by Dave C
    Hello, I have several buttons on my app that are being created dynamically. They are all pointed at the button click event when pressed. When the button pressed method is called, the sender's tag(int value) is parsed into the controllers house ID. It works with one of the buttons... the first one created to be specific, but the others throw the following error: -[CFNumber intValue]: message sent to deallocated instance 0xc4bb0ff0 I am not releasing these buttons anywhere in my code... I haven't set them to auto release or anything like that... just wondering why they are doing this on the click. The button click event: - (IBAction) ButtonClick: (id) sender { HouseholdViewController *controller = [[HouseholdViewController alloc] initWithNibName:@"HouseholdViewController" bundle:nil]; controller.delegate = self; controller.HouseID = [(NSInteger)[(UIButton *)sender tag] intValue]; //this line throws an error controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; [controller release]; } Where I am creating the buttons: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(MyLongInScreenCoords, MyLatInScreenCoords, 50, 50); UIImage *buttonImageNormal = [UIImage imageNamed:@"blue_pin.png"]; UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:50 topCapHeight:50]; [button setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal]; [self.view addSubview:button]; button.tag = [NSNumber numberWithInt:[[words objectAtIndex: i] intValue]]; ButtonPoints[CurrentHouseCount][0] = button; ButtonPoints[CurrentHouseCount][1] = [NSValue valueWithCGPoint:CGPointMake(MyActualLat, MyActualLong)]; [button addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside]; CurrentHouseCount++; Thank you for any assistance.

    Read the article

  • How can i attached iphone image through mail in iphone

    - by Pugal Devan
    Hi, I am new to iphone development. I have created a button in the view. On clicking the button it loads the photolibrary from the Iphone. Now i want to attached the those selected image through mail. I donno how to attach the image in MFMailComposerView. How can i achieve this, Here my code is, -(IBAction) Pictures:(id)sender { self.imgpicker = [[UIImagePickerController alloc] init]; self.imgpicker.delegate = self; self.imgpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:self.imgpicker animated:YES]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img1 editingInfo:(NSDictionary *)editInfo { [[picker parentViewController] dismissModalViewControllerAnimated:NO]; UIView *view = [[UIView alloc] init]; (This view for displaying the images) imageview = [[UIImageView alloc] initWithImage:img1]; [imageview setFrame:CGRectMake(0, 0, 320, 420)]; [self.view addSubview:imageview]; [view release]; UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithTitle:@"Email" style:UIBarButtonItemStyleBordered target:self action:@selector(rightbutton)]; self.navigationItem.rightBarButtonItem = rightbutton; [rightbutton release]; } -(void) rightbutton { [self emailImage:(UIImage *)image];( how to pass the image to mail view) } - (void)emailImage:(UIImage *)image { picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; NSData *data = UIImagePNGRepresentation(image); [picker addAttachmentData:data mimeType:@"image/png" fileName:@"iPod Library Image"]; [self presentModalViewController:picker animated:YES]; [picker release]; } Please help me out. Thanks.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >