ios proper way to update programatic uilabels with viewdidappear - iphone

Every time this tab get loaded instead of updating the dynamic label, it writes a brand new label over it. What do I need to put in this code so that it updates it or clears the dynamic labels and then put in the new label. I feel like its probably just a simple one line fix. Here is a simplified version of the code:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
goalArray = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://localhost/goal.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:test forKey:#"name"];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIFormDataRequest *)request
{
...
for (id myArrayElement in goalArray)
{
NSLog(#"y value:%i", yValue);
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(0, yValue, 80, 44)];
label.font = [UIFont systemFontOfSize:12];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.text = myArrayElement;
[self.view addSubview:label];
yValue += 44;
}
}

In requestFinished: before the for loop, add this:
for ( UIView *die in [self subviews]) { // clear out previous label
if ( die.tag == 123 ) {
[die removeFromSuperview];
}
}
and then inside your for loop, add this:
label.tag = 123; //doesn't have to be 123, as long as it's an int that matches the one above.

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?

Performing different actions on same button click during Runtime (Similar to twitter Follow/UnFollow)?

I have the following program structure:
-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
...
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
...
...
if(condition)
{
do something;
}
else
{
if(condition)
{
unFollowButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
unFollowButton.frame = CGRectMake(180, 10, 120, 30);
unFollowButton.titleLabel.font = [UIFont systemFontOfSize:12];
unFollowButton.tag = indexPath.row;
unFollowButton.titleLabel.textColor = [UIColor blackColor];
[unFollowButton addTarget:self action:#selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
NSLog(#"fCheckRowCheck Value in if Condition %#",fCheckRowCheck);
[unFollowButton setTitle:#"UnFollow" forState:UIControlStateNormal];
[cell.contentView addSubview:unFollowButton];
buttonValue = 0;
NSLog(#"buttonValue %d", buttonValue);
}
else
{
followButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
followButton.frame = CGRectMake(180, 10, 120, 30);
followButton.titleLabel.font = [UIFont systemFontOfSize:12];
followButton.tag = indexPath.row;
followButton.titleLabel.textColor = [UIColor blackColor];
[followButton setTitle:#"Follow" forState:UIControlStateNormal];
[followButton addTarget:self action:#selector(buttonClicked1:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:followButton];
buttonValue = 1;
NSLog(#"buttonValue %d", buttonValue);
}
}
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.infos objectAtIndex:row];
return cell;
}
- (IBAction)buttonClicked2:(UIButton *)sender
{
NSLog(#"BUTTON_CLICKED");
NSIndexPath *indexPath = [folksFolksTable indexPathForCell:(UITableViewCell*) [[sender superview]superview]];
NSLog(#"[sender tag] is %d", [sender tag]);
....
....
....
//Set up URLConnection tp send information on button click
NSMutableString *postString = [NSMutableString stringWithString:kUnFollowURL];
[postString appendString: [NSString stringWithFormat:#"?%#=%#", kId, [user objectForKey:#"id"] ]];
[postString appendString: [NSString stringWithFormat:#"&%#=%#", kfId, [fId objectForKey:#"fID"] ]];
[postString setString: [postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(#"post string = %#", postString);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:#"POST"];
followConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
NSLog(#"postconnection: %#", followConnection);
//Get Response from server
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: postString ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
NSLog(#"serverOutput = %#", serverOutput);
//Change the button lable from unfollow to follow
[sender setTitle:#"Follow" forState:UIControlStateNormal];
if([sender tag]==indexPath.row)
{
textField = (UITextField*)[cell viewWithTag:[sender tag]];
NSLog(#"txtF is %#",textField);
textField.hidden=NO;
}
}
- (IBAction)buttonClicked1:(UIButton *)sender
{
similar to buttonClicked 2
}
What I need is that the button should perform the corresponding action as well after the label has changed during runtime.
For example, I am following someone [ button label unfollow], if i click on the button [ button label becomes follow at that instant ( which is happening perfectly OK ). Now when i click the same button again with "follow" label, it is throwing exception.
How to go about it. Please help me figure it out ?
I'm new to iOS but:
Set a property that has the button state, or extend the button (some people don't recommend)
When it changes state, change the color and the label.
Wouldn't that work. Probably other users have better solutions.
Cheers.
EDIT: solved it. I had added previously the following line of code after
[sender setTitle:#"Follow" forState:UIControlStateNormal];
[sender addTarget:self action:#selector(buttonClicked2:) forControlEvents:UIControlEventTouchUpInside];
cause of exception was i added colon (:) twice after #selector(buttonClicked2) whereas i need only one colon.
I hope this question serves as reference to other users as well.

How to stop mutiple activity indicator animation in multiple webview?

Currently i am developing a sample where i am displaying 4 webview in ipad screen and trying to show 4 different URL in them.
All the web pages are showing in the webview perfectly.
Also i am displaying 4 activity indicator once the webpage starts loading.
But i can not figure out how to stop activity indicator in all the respective webpage one by one once they are loaded in to the screen.
-(void)createWebView
{
//******************** First *********
firstWebView=[[UIWebView alloc]init];
firstWebView.frame=CGRectMake(10, 50, 350, 470);
firstWebView.delegate=self;
firstIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
firstIndicator.center = CGPointMake(160, 240);
firstIndicator.hidesWhenStopped = YES;
[self.firstWebView addSubview:firstIndicator];
[firstIndicator startAnimating];
firstWebView.backgroundColor=[UIColor grayColor];
NSURL *firstUrl = [NSURL URLWithString:#"http://www.techtree.com"];
NSURLRequest *firstRequestObj = [NSURLRequest requestWithURL:firstUrl];
[firstWebView loadRequest:firstRequestObj];
[self.view addSubview:firstWebView];
//******************* Second *********
secondWebView=[[UIWebView alloc]init];
secondWebView.frame=CGRectMake(405, 50, 350, 470);
secondWebView.delegate=self;
secondIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
secondIndicator.center = CGPointMake(160, 240);
secondIndicator.hidesWhenStopped = YES;
[self.secondWebView addSubview:secondIndicator];
[secondIndicator startAnimating];
secondWebView.backgroundColor=[UIColor grayColor];
NSURL *secondUrl = [NSURL URLWithString:#"http://www.facebook.com"];
NSURLRequest *secondRequestObj = [NSURLRequest requestWithURL:secondUrl];
[secondWebView loadRequest:secondRequestObj];
[self.view addSubview:secondWebView];
//****************** Third ************
thirdWebView=[[UIWebView alloc] init];
thirdWebView.frame=CGRectMake(10, 528, 350, 470);
thirdWebView.delegate=self;
thirdIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
thirdIndicator.center = CGPointMake(160, 240);
thirdIndicator.hidesWhenStopped = YES;
[self.thirdWebView addSubview:thirdIndicator];
[thirdIndicator startAnimating];
thirdWebView.backgroundColor=[UIColor grayColor];
NSURL *thirdUrl = [NSURL URLWithString:#"http://www.yahoo.com"];
NSURLRequest *thirdRequestObj = [NSURLRequest requestWithURL:thirdUrl];
[thirdWebView loadRequest:thirdRequestObj];
[self.view addSubview:thirdWebView];
//***************** Fourth ************
fourthWebView=[[UIWebView alloc] init];
fourthWebView.frame=CGRectMake(405,528, 350, 470);
fourthWebView.delegate=self;
fourthIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
fourthIndicator.center = CGPointMake(160, 240);
fourthIndicator.hidesWhenStopped = YES;
[self.fourthWebView addSubview:fourthIndicator];
[fourthIndicator startAnimating];
fourthWebView.backgroundColor=[UIColor grayColor];
NSURL *fourthUrl = [NSURL URLWithString:#"http://stackoverflow.com"];
NSURLRequest *fourthRequestObj = [NSURLRequest requestWithURL:fourthUrl];
[fourthWebView loadRequest:fourthRequestObj];
[self.view addSubview:fourthWebView];
//******************** Memory Managemt **********
[firstWebView release];
[secondWebView release];
[thirdWebView release];
[fourthWebView release];
[firstIndicator release];
[secondIndicator release];
[thirdIndicator release];
[fourthIndicator release];
}
overwrite below delegate method and check which webview is loading finished like below
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if(webView== firstWebView)
{
[firstIndicator setHidden:YES];
}
else
{
so on...
}
}

Multiple loading of webpages in webview is slower

I am developing an sample iPad app where I am displaying some webapages in UIWebview , the code is working properly.But I think the webpages are taking too much time to load in to UIWebview.My code is as below:
-(void)createWebView
{
//******************** First Webview*********
firstWebView=[[UIWebView alloc]init];
firstWebView.frame=CGRectMake(10, 50, 350, 470);
firstWebView.delegate=self;
firstIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
firstIndicator.center = CGPointMake(160, 240);
firstIndicator.hidesWhenStopped = YES;
[self.firstWebView addSubview:firstIndicator];
[firstIndicator startAnimating];
firstWebView.backgroundColor=[UIColor grayColor];
NSURL *firstUrl = [NSURL URLWithString:#"http://www.techtree.com"];
NSURLRequest *firstRequestObj = [NSURLRequest requestWithURL:firstUrl];
[firstWebView loadRequest:firstRequestObj];
[self.view addSubview:firstWebView];
//******************* Second Webview*********
secondWebView=[[UIWebView alloc]init];
secondWebView.frame=CGRectMake(405, 50, 350, 470);
secondWebView.delegate=self;
secondIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
secondIndicator.center = CGPointMake(160, 240);
secondIndicator.hidesWhenStopped = YES;
[self.secondWebView addSubview:secondIndicator];
[secondIndicator startAnimating];
secondWebView.backgroundColor=[UIColor grayColor];
NSURL *secondUrl = [NSURL URLWithString:#"http://www.facebook.com"];
NSURLRequest *secondRequestObj = [NSURLRequest requestWithURL:secondUrl];
[secondWebView loadRequest:secondRequestObj];
[self.view addSubview:secondWebView];
//****************** Third Webview************
thirdWebView=[[UIWebView alloc] init];
thirdWebView.frame=CGRectMake(10, 528, 350, 470);
thirdWebView.delegate=self;
thirdIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
thirdIndicator.center = CGPointMake(160, 240);
thirdIndicator.hidesWhenStopped = YES;
[self.thirdWebView addSubview:thirdIndicator];
[thirdIndicator startAnimating];
thirdWebView.backgroundColor=[UIColor grayColor];
NSURL *thirdUrl = [NSURL URLWithString:#"http://www.yahoo.com"];
NSURLRequest *thirdRequestObj = [NSURLRequest requestWithURL:thirdUrl];
[thirdWebView loadRequest:thirdRequestObj];
[self.view addSubview:thirdWebView];
//***************** Fourth Webview************
fourthWebView=[[UIWebView alloc] init];
fourthWebView.frame=CGRectMake(405,528, 350, 470);
fourthWebView.delegate=self;
fourthIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
fourthIndicator.center = CGPointMake(160, 240);
fourthIndicator.hidesWhenStopped = YES;
[self.fourthWebView addSubview:fourthIndicator];
[fourthIndicator startAnimating];
fourthWebView.backgroundColor=[UIColor grayColor];
NSURL *fourthUrl = [NSURL URLWithString:#"http://stackoverflow.com"];
NSURLRequest *fourthRequestObj = [NSURLRequest requestWithURL:fourthUrl];
[fourthWebView loadRequest:fourthRequestObj];
[self.view addSubview:fourthWebView];
//******************** Memory Managemt **********
[firstWebView release];
[secondWebView release];
[thirdWebView release];
[fourthWebView release];
}
So how can I make it more faster, please guide me.
For this you have to use NSOpertaionQueue or GCD queue is another options

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
}