Skip to content

Instantly share code, notes, and snippets.

@pnicholls
Created July 2, 2011 07:53
Show Gist options
  • Save pnicholls/1059832 to your computer and use it in GitHub Desktop.
Save pnicholls/1059832 to your computer and use it in GitHub Desktop.
- (void)setPageIndex:(NSInteger)newPageIndex
{
pageIndex = newPageIndex;
if (pageIndex >= 0 && pageIndex < [[DataSource sharedDataSource] numDataPages])
{
// NSArray *pageData =
// [[DataSource sharedDataSource] dataForPage:pageIndex];
//
// image_one.image = [pageData objectAtIndex:0];
// image_two.image = [pageData objectAtIndex:1];
[image_one.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[image_one.layer setBorderWidth: 5.0];
image_one.layer.shadowColor = [UIColor grayColor].CGColor;
image_one.layer.shadowOffset = CGSizeMake(0, 1);
image_one.layer.shadowOpacity = 1;
image_one.layer.shadowRadius = 1.0;
image_one.opaque = YES; // explicitly opaque for performance
image_one.userInteractionEnabled = YES;
[image_two.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[image_two.layer setBorderWidth: 5.0];
image_two.layer.shadowColor = [UIColor grayColor].CGColor;
image_two.layer.shadowOffset = CGSizeMake(0, 1);
image_two.layer.shadowOpacity = 1;
image_two.layer.shadowRadius = 1.0;
image_two.opaque = YES; // explicitly opaque for performance
image_two.userInteractionEnabled = YES;
NSDictionary *pageData =
[[DataSource sharedDataSource] dataForPage:pageIndex];
//Get the picture for the profile pic
NSString *urlString = [pageData objectForKey:@"1"];
NSURL *url = [NSURL URLWithString:urlString];
//setup request
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
request.numberOfTimesToRetryOnTimeout = 3;
[request setCompletionBlock:^(void) {
//create a UIImage using response data
UIImage *image = [UIImage imageWithData:[request responseData]];
//set the image on the main thread
[image_one performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
}];
[request setFailedBlock:^(void) {
//On error, display the error in an alert view
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[[request error] description] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
[alert show];
[alert release];
}];
//start the request
[request startAsynchronous];
CGRect absoluteRect = [self.view.window
convertRect:textView.bounds
fromView:textView];
if (!self.view.window ||
!CGRectIntersectsRect(
CGRectInset(absoluteRect, TEXT_VIEW_PADDING, TEXT_VIEW_PADDING),
[self.view.window bounds]))
{
textViewNeedsUpdate = YES;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment