Temporary release memory - iphone

I am creating a quiz app in iPhone.
So that i have so many labels and buttons in use at a time.
If i release them right after one question then application stops.
If i am not doing that and releasing them at dealloc function then it shows memory warning and app crashes.
I am using this Code
received memory warning. level 1
If i set around 20 questions then application is not crashing but if i add more questions then it crashes..
I think it is allocating memory and not releasing right after one question.
Please help me out this:(
Edited :
I am using this code after selecting answer
-(void)checkAnswer:(int)theAnswerValue
{
[AVback stop];
[scrollview scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
[Challengetext setHidden:YES];
[theScore setHidden:YES];
[theQuestion setHidden:NO];
[Question setHidden:YES];
if(rightAnswer == theAnswerValue)
{
NSString *AVpath = [[NSBundle mainBundle] pathForResource:#"Winner_1" ofType:#"m4a"];
AVAudioPlayer *AVbtn1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:AVpath] error:NULL];
[img1 setHidden:NO];
[img2 setHidden:YES];
[theQuestion setFont:[UIFont fontWithName:#"Futura" size:30]];
theQuestion.textColor = [UIColor purpleColor];
theQuestion.text = #"\n\nCorrect Answer!!";
[rightans setHidden:NO];
[Description setHidden:NO];
[ContainerView setHidden:NO];
myScore = myScore + 50;
}
else
{
NSString *AVpath = [[NSBundle mainBundle] pathForResource:#"incorrect2" ofType:#"m4a"];
AVAudioPlayer *AVbtn1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:AVpath] error:NULL];
QuizAppUniversalAppDelegate *appDelegate = (QuizAppUniversalAppDelegate *) [[UIApplication sharedApplication] delegate];
if(appDelegate.soundIndicator == 0){
[AVbtn1 play];
}
else{
[AVback stop];
[AVstart stop];
[AVbtn1 stop];
}
[img2 setHidden:NO];
[img1 setHidden:YES];
[theQuestion setFont:[UIFont fontWithName:#"Futura" size:30]];
theQuestion.textColor = [UIColor redColor];
theQuestion.text = #"\nIncorrect Answer!!\nRight answer is : \n ";
[rightans setHidden:NO];
[Description setHidden:NO];
[ContainerView setHidden:NO];
myScore = myScore ;
}
Thanks.. Any help will be appreciated.. !!

You don't appear to be releasing your avBtn1 object anywhere, and you are allocating a new one every time checkAnswer is called. Is that dealt with somewhere else in the code?

Related

ImageGallery image in black for ios 7

In my efforts to upgrade my application to support IOS7 I found out that ImageGallery don't load the images. in others iOS is ok.
In imageGalleryView:
- (void)initWithPhotos:(NSMutableArray *)photoURLStrings andCaptions:(NSArray *)myCaptions moveToPage:(int)page {
captions = [myCaptions copy];
photoUrls = [photoURLStrings copy];
NSLog(#"array---> %#", photoUrls);
photoLoaded = [[NSMutableArray alloc] init];
for (int i=0; i<[photoURLStrings count]; i++) {
[photoLoaded addObject:[NSNumber numberWithBool:FALSE]];
}
[pageControl setNumberOfPages:[photoUrls count]];
//scrollView= [[UIScrollView alloc] init];
scrollView.backgroundColor = [UIColor blackColor];
scrollView.pagingEnabled = TRUE;
scrollView.autoresizesSubviews = TRUE;
scrollView.contentSize = CGSizeMake(320 * [photoUrls count], scrollView.frame.size.height);
scrollView.contentOffset = CGPointMake(self.scrollView.frame.size.width*page, 0);
if (([captions objectAtIndex:page] == nil) || ([[captions objectAtIndex:page] isEqualToString:#""])) {
[textView setHidden:TRUE];
} else {
[textView setHidden:FALSE];
[textView setText:[captions objectAtIndex:page]];
}
[self showImages:page];}
- (void)showImages:(int)page {
AsyncImageViewController *asyncImageView;
if ((page>=0)&&(page<[photoUrls count])) {
if (![[photoLoaded objectAtIndex:page] boolValue]) {
[photoLoaded replaceObjectAtIndex:page withObject:[NSNumber numberWithBool:TRUE]];
asyncImageView = [[AsyncImageViewController alloc] init];
//NSLog(#"%#",[NSString stringWithFormat:#"%#",[photoUrls objectAtIndex:page]]);
[asyncImageView loadImageFromURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",[photoUrls objectAtIndex:page]]] pos:1];
//NSLog(#"page:%i",page);
asyncImageView.frame = CGRectMake(320*page,0,320,scrollView.frame.size.height);
//[scrollView setBackgroundColor:[UIColor colorWithPatternImage:asyncImageView.image]];
[scrollView addSubview:asyncImageView];
[asyncImageView release];
}
}
page = page - 1;
if ((page>=0)&&(page<[photoUrls count])) {
if (![[photoLoaded objectAtIndex:page] boolValue]) {
[photoLoaded replaceObjectAtIndex:page withObject:[NSNumber numberWithBool:TRUE]];
asyncImageView = [[AsyncImageViewController alloc] init];
[asyncImageView loadImageFromURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",[photoUrls objectAtIndex:page]]] pos:1];
asyncImageView.frame = CGRectMake(320*page,0,320,scrollView.frame.size.height);
[scrollView addSubview:asyncImageView];
[asyncImageView release];
}
}
page = page + 2;
if ((page>=0)&&(page<[photoUrls count])) {
if (![[photoLoaded objectAtIndex:page] boolValue]) {
[photoLoaded replaceObjectAtIndex:page withObject:[NSNumber numberWithBool:TRUE]];
asyncImageView = [[AsyncImageViewController alloc] init];
[asyncImageView loadImageFromURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",[photoUrls objectAtIndex:page]]] pos:1];
asyncImageView.frame = CGRectMake(320*page,0,320,scrollView.frame.size.height);
[scrollView addSubview:asyncImageView];
//[scrollView setBackgroundColor:[UIColor colorWithPatternImage:asyncImageView.image]];
[asyncImageView release];}}}
In the asyncimageview:
- (void)loadImageFromURL:(NSURL*)url pos:(int) posicio {
if (connection!=nil) { [connection release]; }
if (data!=nil) { [data release]; }
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
if (posicio == 0) {
loading.center = CGPointMake(75/2,75/2);
}else {
loading.center = CGPointMake(160,210);
}
[loading startAnimating];
[self addSubview:loading];
[loading release];}//the URL connection calls this repeatedly as data arrives- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; }
[data appendData:incrementalData];}//the URL connection calls this once all the data has downloaded- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
//so self data now has the complete image
[connection release];
connection=nil;
if ([[self subviews] count]>0) {
//then this must be another image, the old one is still in subviews
[[[self subviews] objectAtIndex:0] removeFromSuperview]; //so remove it (releases it also)
}//make an image view for the image
imageView = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
//make sizing choices based on your needs, experiment with these. maybe not all the calls below are needed.
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight );
//[self setBackgroundColor:[UIColor colorWithPatternImage:imageView]];
[self addSubview:imageView];
imageView.frame = self.bounds;
[imageView setNeedsLayout];
[self setNeedsLayout];
[loading stopAnimating];
[data release]; //don't need this any more, its in the UIImageView now
data=nil;}
//just in case you want to get the image directly, here it is in subviews- (UIImage*) image {
UIImageView* iv = [[self subviews] objectAtIndex:0];
return [iv image];}
I checked all and saw that it is UIView instead of UIImageView. probably Apple changed something. But xCode don't throw any errors.
Any idea how to fix it?

how to continue playing second song after first song is finished playing in AVPlayer

How can I start next song immediately with AVPlayer? I have collections of song selected from iPod Library in MPMediaItemCollection which is shown in my UITableView [myPlaylistTable] . i know i have to use NSNotification to check whether song has finished ,but i dont know how to play the second or next song as soon as the current song finish playing .I have posted my code below
If anyone can help me with the solution it would be appreciated.
Thanks
in viewDidLoad i have initialized
- (void)viewDidLoad
{
[super viewDidLoad];
//[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self.myPlaylistTable deselectRowAtIndexPath:[self.myPlaylistTable indexPathForSelectedRow] animated:NO];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 0;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryMixWithOthers,
sizeof (doSetProperty),
&doSetProperty
);
[self becomeFirstResponder];
myPlaylistTable.hidden=YES;
playlistSongsArray =[[NSMutableArray alloc]init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(nextSongPlaying:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[myPlayer currentItem]];
}
-(void) mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
// Dismiss selection view
[self dismissViewControllerAnimated:YES completion:nil];
// Get AVAsset
NSURL* assetUrl = [mediaItemCollection.representativeItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:assetUrl options:nil];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:asset];
myPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[playlistSongsArray addObjectsFromArray:mediaItemCollection.items];
NSLog(#" Playlist songs %#",playlistSongsArray);
[self.myPlaylistTable reloadData];
[myPlayer play];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (UITableViewCell *) tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
NSInteger row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellIdentifier];
UILabel *playbackDurationLabel =[[UILabel alloc]initWithFrame:CGRectMake(205, 88, 103, 18)];
playbackDurationLabel.tag = 100;
playbackDurationLabel.backgroundColor = [UIColor clearColor];
playbackDurationLabel.textColor = [UIColor orangeColor];
playbackDurationLabel.font = [UIFont fontWithName:#"Helvetica" size:14];
[cell.contentView addSubview:playbackDurationLabel];
}
if (tableView == myPlaylistTable)
{
MPMediaItem *mediaItem = (MPMediaItem *)[playlistSongsArray objectAtIndex:row];
MPMediaItemArtwork *artwork = [mediaItem valueForProperty:MPMediaItemPropertyArtwork];
if (mediaItem)
{
cell.textLabel.text = [mediaItem valueForProperty:MPMediaItemPropertyTitle];
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:15];
cell.textLabel.numberOfLines=0;
cell.detailTextLabel.text = [mediaItem valueForProperty:MPMediaItemPropertyArtist];
cell.detailTextLabel.textColor = [UIColor blueColor];
cell.detailTextLabel.font = [UIFont fontWithName:#"Helvetica" size:14];
cell.detailTextLabel.numberOfLines=0;
UILabel *songDurationLabel = (UILabel *) [cell.contentView viewWithTag:100];
songDurationLabel.text=[self secondsFormatted:[[mediaItem valueForProperty:MPMediaItemPropertyPlaybackDuration] intValue]];
NSLog(#"song duration - %#",[[mediaItem valueForProperty:MPMediaItemPropertyPlaybackDuration] stringValue]);
if (artwork != nil)
{
cell.imageView.image = [artwork imageWithSize:CGSizeMake(60, 60)];
}
else
{
cell.imageView.image = [UIImage imageNamed:#"noArtworkImage.png"];
}
}
[tableView deselectRowAtIndexPath: indexPath animated: YES];
}
return cell;
}
-(void)nextSongPlaying:(NSNotification *)notification
{
//What stuff to do
}
DShah i did it this way ..can u check if it is correct in my viewDidLoad ..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(nextSongPlaying:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[myPlayer currentItem]];
- (void)nextSongPlaying:(NSNotification *)notification
{
AVPlayerItem *playerItem = [notification object];
[playerItem seekToTime:kCMTimeZero];
[myPlayer play];
}
Please refer to the Apple's Link for help : http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html
This link explain about Playing Multiple Items. You can use AVQueuePlayer which is subclass of AVPlayer for queuing the multiple songs.
EDIT
Please see the GitHub link : https://github.com/crocodella/AVPlayerSample
For explanation : http://www.crocodella.com.br/2011/01/using-avplayer-to-play-background-music-from-library/
This link has same thing that you want.

UISwitch with AVAudioPlayer

Have problem in playsound section.When i turn switch off - soundchecker change his value to NO,but audioplayer not stopping.What's wrong guys?
-(IBAction)Settings {
if(settingsview==nil) {
settingsview=[[UIView alloc] initWithFrame:CGRectMake(10, 130, 300, 80)];
[settingsview setBackgroundColor:[UIColor clearColor]];
UILabel *labelforSound = [[UILabel alloc]initWithFrame:CGRectMake(15, 25, 70, 20)];
[labelforSound setFont:[UIFont systemFontOfSize:18]];
[labelforSound setBackgroundColor:[UIColor clearColor]];
[labelforSound setText:#"Sound"];
SoundSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(10, 50, 20, 20)];
SoundSwitch.userInteractionEnabled = YES;
if(soundchecker == YES) [SoundSwitch setOn:YES];
else [SoundSwitch setOn:NO];
[SoundSwitch addTarget:self action:#selector(playsound:) forControlEvents:UIControlEventValueChanged];
[settingsview addSubview:labelforSound];
[settingsview addSubview:SoundSwitch];
[self.view addSubview:settingsview];
}
else {
[settingsview removeFromSuperview];
[settingsview release];
settingsview=nil;
}
}
//-------Playsound------------------//
-(void)playsound:(id) sender {
NSString *pathtosong = [[NSBundle mainBundle]pathForResource:#"Teachme" ofType:#"mp3"];
AVAudioPlayer* audioplayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathtosong] error:NULL];
if(SoundSwitch.on) {
[audioplayer play];
soundchecker = YES;
}
if(!SoundSwitch.on) {
[audioplayer stop];
soundchecker = NO;
}
}
It's not stopping because every time that playsound is called you are creating a NEW AVAudioPlayer. So when you call [audioplayer stop], you are not calling it on the AVAudioPlayer that is currently playing, you are calling it on a new one you just created.
You could add the AVAudioPlayer variable to the header of your class (as a property if you want). Then you could do this:
-(void)playsound:(id) sender
{
if(SoundSwitch.on)
{
if(!audioPlayer) {
NSString *pathtosong = [[NSBundle mainBundle]pathForResource:#"Teachme" ofType:#"mp3"];
audioplayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathtosong] error:nil];
}
[audioplayer play];
soundchecker = YES;
} else {
if(audioPlayer && audioPlayer.isPlaying) {
[audioplayer stop];
}
soundchecker = NO;
}
}

UIButton view unrecognized selector sent to instance

Basically i have a UIToolbar on the main window and when i hit the infobutton to open a modal view application is crashing with output message that UIButton view unrecognized selector sent to instance. Can someone please help me to solve this output message.
UIButton *infoItem = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
infoItem.frame = CGRectMake(250.0, 8.0, 25.0, 25.0);
infoItem.backgroundColor = [UIColor clearColor];
[infoItem addTarget:self action:#selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
infoItem.backgroundColor = [UIColor grayColor];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
NSArray *toolbarItems = [NSArray arrayWithObjects: settingsButton, flexItem, systemItem, flexItem, systemItem1,flexItem, systemItem2, flexItem, systemItem3, flexItem, infoItem, nil];
[toolbar setItems:toolbarItems];
[settingsButton release];
[systemItem release];
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[infoItem release];
[flexItem release];
[super viewDidLoad];
- (void) playaudio: (id) sender {
// Get the file path to the song to play.
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"theme"
ofType:#"mp3"];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
//Initialize the AVAudioPlayer.
self.audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
// Making sure the audio is at the start of the stream.
self.audioPlayer.currentTime = 0;
[self.audioPlayer play];
}
- (void)pause: (id)sender {
if
([audioPlayer isPlaying])
{[audioPlayer pause];}
else
{[audioPlayer play];}
}
- (void)stop: (id) sender
{
[audioPlayer stop];
}
- (void)displayModalViewaction
{
self.viewController = [[Infoviewcontroller alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] init];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[self.view addSubview:navigationController.view];
}
Appreciate help to solve this.
Thanks in advance.
[infoItem addTarget:self action:#selector(displayModalViewaction:) forControlEvents:UIControlEventTouchUpInside];
infoItem.backgroundColor = [UIColor grayColor];
should be
[infoItem addTarget:self action:#selector(displayModalViewaction) forControlEvents:UIControlEventTouchUpInside];
infoItem.backgroundColor = [UIColor grayColor];
because displayModalViewaction do not receive any parameters.
use #selector(displayModalViewaction) to add event;
or change method define with: -(void)displayModalViewaction:(id)sender;

iPhone crash.. no console error

Update
I turned Zombies on... and got this error:
*** -[CALayer retain]: message sent to deallocated instance 0x709d1a0
I'm experiencing a crash that does not make any sense to me. In loadMediaList I'm programmatically creating multiple buttons and assigning an action(openMedia:) to them. That action has an "openURL" action. Everything works great, until the action is called; the action is performed, opened up in a new window, but then crashes once the app is exited. I replaced the "openURL" code with different code, and it still crashes... thoughts?
There is no error in the console, I get EXC_BAD_ACCESS. The console says:
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
kill
quit
Program ended with exit code: 0
I have been working on this issue for a few days now and I cannot figure it out. my dealloc is great, threads seem to be working well, etc. I don't know if this is legal on Stack Overflow, but I will gladly pay someone to help me solve this. I have a very tight deadline.
Hope you can help!
-(IBAction)showMedia:(id)sender {
NSLog(#"Media Button was pressed");
//Begin Alert
[SVProgressHUD showInView:self.view status:#"Loading..."];
mediaScroll.delegate = self;
mediaScroll.frame = CGRectMake(15, 60, 240, 185);
mediaScroll.clipsToBounds = YES;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
statsBTN.frame = CGRectMake(272, 76, 48, 46);
donateBTN.frame = CGRectMake(272, 124, 48, 46);
shareBTN.frame = CGRectMake(272, 172, 48, 46);
mediaBTN.frame = CGRectMake(280, 220, 48, 46);
incViewPopUP.alpha = 0;
donViewPopUP.alpha = 0;
shareViewPopUP.alpha = 0;
mediaViewPopUP.alpha = 1;
[UIView commitAnimations];
[self loadMediaList];
[mediaBTN addTarget:self action:#selector(closePopUp:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)loadMediaList {
[self.productPointers removeAllObjects];
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:#"date_reported" ascending:NO] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray = [finalMediaList sortedArrayUsingDescriptors:sortDescriptors];
NSLog(#"Sorted Media Array: %#", sortedArray);
if (mediaLoaded == NO) {
NSDictionary *mediaPost;
for (mediaPost in sortedArray) {
NSDictionary *inside = (NSDictionary *)[mediaPost valueForKey:#"media"];
NSLog(#"Inside Array: %#", inside);
UIButton *mediaView = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
mediaView.frame = CGRectMake(0, (mx * 100), 225, 100);
mediaView.backgroundColor = [UIColor clearColor];
[mediaView addTarget:self action:#selector(openMedia:) forControlEvents:UIControlEventTouchUpInside];
mediaView.titleLabel.hidden = YES;
mediaView.titleLabel.alpha = 0;
mx++; NSLog(#"MX: %i", mx);
UILabel *mediaDesc = [[UILabel alloc] init];
mediaDesc.frame = CGRectMake(50, 20, 154, 40);
mediaDesc.backgroundColor = [UIColor clearColor];
mediaDesc.font = [UIFont fontWithName:#"Geogrotesque" size:12];
mediaDesc.textColor = UIColorFromRGB(0xc7c7c7);
mediaDesc.numberOfLines = 0;
mediaDesc.lineBreakMode = UILineBreakModeWordWrap;
mediaDesc.text = [inside valueForKey:#"description"];
UILabel *mediaType = [[UILabel alloc] init];
mediaType.frame = CGRectMake(50, 40, 154, 50);
mediaType.backgroundColor = [UIColor clearColor];
mediaType.font = [UIFont fontWithName:#"Geogrotesque" size:12];
mediaType.textColor = UIColorFromRGB(0xffffff);
mediaType.numberOfLines = 0;
mediaType.lineBreakMode = UILineBreakModeWordWrap;
mediaType.text = [[inside valueForKey:#"type"] uppercaseString];
UIImageView *mediaBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0, 99.0, 220.0, 1.0)];
[mediaBorder setImage:[UIImage imageNamed:#"bottom_border.png"]];
UIImageView *mediaArrow = [[UIImageView alloc] initWithFrame:CGRectMake(214.0, 45.0, 6.0, 9.0)];
[mediaArrow setImage:[UIImage imageNamed:#"media_right_arrow.png"]];
if ([mediaType.text isEqualToString:#"VIDEO"]) {
UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 30.0)] autorelease];
[mediaThumb setImage:[UIImage imageNamed:#"media_play_icon.png"]];
[mediaView addSubview:mediaThumb];
[mediaThumb release];
[mediaView setTag:1];
[mediaView setTitle:[inside valueForKey:#"filename"] forState:UIControlStateNormal];
}
if ([mediaType.text isEqualToString:#"IMAGE"]) {
UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 22.0)] autorelease];
[mediaThumb setImage:[UIImage imageNamed:#"media_photo_icon.png"]];
[mediaView addSubview:mediaThumb];
[mediaThumb release];
[mediaView setTag:2];
[mediaView setTitle:[inside valueForKey:#"url"] forState:UIControlStateNormal];
}
[mediaView addSubview:mediaArrow];
[mediaView addSubview:mediaBorder];
[mediaView addSubview:mediaDesc];
[mediaView addSubview:mediaType];
[mediaScroll addSubview:mediaView];
[self.productPointers addObject:mediaView];
[mediaArrow release];
[mediaBorder release];
[mediaType release];
[mediaDesc release];
[mediaView release];
}
}
mediaLoaded = YES;
[mediaScroll setContentSize:CGSizeMake(225.0f, (mx * 100))];
//End Alert
[SVProgressHUD dismiss];
}
-(IBAction)openMedia:(id)sender {
NSLog(#"Media opened!");
NSString *tag = [NSString stringWithFormat:#"%d", [sender tag]];
NSLog(#"Tag: %#", tag);
videoID = [sender currentTitle];
NSString *videoURL = [[[NSString alloc] initWithFormat:#"http://www.vimeo.com/%#", videoID] autorelease];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
NSLog(#"Video URL: %#", videoURL);
}
Turn on malloc stack logging, guard malloc, and zombie enabled in the debugger, then run:
(gdb) info malloc-history 0x1b18b0
Where 0x1b18b0 is the address of the thing that has the bad access error. It should give you more info about where in your code the problem is.
See this article for better instructions
Also, some code thoughts that may help
change this:
videoID = [sender currentTitle];
NSString *videoURL = [[[NSString alloc] initWithFormat:#"http://www.vimeo.com/%#", videoID] autorelease];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
To:
videoID = [sender currentTitle];
if (videoID) {
// no need to alloc then set autorelease, just used a named initializer since they autorelease by default:
NSString *videoURL = [NSString stringWithFormat:#"http://www.vimeo.com/%#", videoID];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
} else {
// deal
}