Github Source URL: https://github.com/cwRichardKim/RKSwipeCards
So, I need to change up some code in 'DraggableViewBackground.m'.
rather than an array of text as is on the stock source code, I need to create an array of images...
Stock section:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[super layoutSubviews];
[self setupView];
exampleCardLabels = [[NSArray alloc]initWithObjects:#"first",#"second",#"third",#"fourth",#"last", nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
return self;
}
I have looked at various implementations of image array, but still comes up with some errors what I can't resolve.
this is my edited code for the array:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[super layoutSubviews];
[self setupView];
exampleCardGraphics = [[NSArray alloc]initWithObjects:00_quote#2x.png, 01_quote#2x.png,02_quote#2x.png,03_quote#2x.png,04_quote#2x.png,05_quote#2x.png,06_quote#2x.png,07_quote#2x.png,08_quote#2x.png,09_quote#2x.png,10_quote#2x.png,11_quote#2x.png,12_quote#2x.png,13_quote#2x.png,14_quote#2x.png,15_quote#2x.png,16_quote#2x.png,17_quote#2x.png,18_quote#2x.png,19_quote#2x.png,20_quote#2x.png,21_quote#2x.png,22_quote#2x.png,23_quote#2x.png,24_quote#2x.png,25_quote#2x.png,26_quote#2x.png,27_quote#2x.png,28_quote#2x.png,29_quote#2x.png,30_quote#2x.png,31_quote#2x.png,32_quote#2x.png,33_quote#2x.png,34_quote#2x.png,35_quote#2x.png,36_quote#2x.png,37_quote#2x.png,38_quote#2x.png,39_quote#2x.png,40_quote#2x.png,41_quote#2x.png,42_quote#2x.png,43_quote#2x.png,44_quote#2x.png,45_quote#2x.png,46_quote#2x.png,47_quote#2x.png,48_quote#2x.png,nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
return self;
}
I get returned "Invalid suffix '_quote' on integer constant"
How would I resolve this to get images pulled into the array, and subsequently one image for each swipe card ?
I have changed a few other things, however only instance names, which have been changed accordingly in corresponding files, so the build still succeeds but I can't get the image array to work.
Please help!
Thanks.
According Apple's docs, SCNMaterial.diffuse.contents can be a AVPlayer.
In this case material appear content of video.
Everything seems ok but I get several sceneKit error logs:
[SceneKit] Error: Could not get pixel buffer (CVPixelBufferRef)
Below is my code. Move [_player play] to viewWillAppear does't help.
- (void)viewDidLoad {
[super viewDidLoad];
self.boxNode = [self.sceneView.scene.rootNode childNodeWithName:#"box" recursively:YES];
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:#"/VRF_SuLie.MP4"];
AVURLAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:path]];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
_player = [AVPlayer playerWithPlayerItem:item];
self.boxNode.geometry.firstMaterial.diffuse.contents = _player;
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[_player play];
}
How to avoid this error?
If it matters:
- I am using storyboards
- Core data
- xcode 4.6
My app has a UITableViewController for a specific view. On that view, if the user clicks a button the software goes through a few processes where data is downloaded from an Internet API and saved into core data. I'm confident this is a resource hog, which is why I am attempting to complete those processes in separate threads.
Note:
- There is an order of operations because legs are dependent on exchanges. Exchanges are dependent on the race and positions. Positions are dependent on the race. Otherwise I would have executed everything asynchronously.
Issues:
- This is my first time working with Grand Central Dispatch. I'm not sure I am doing it correctly.
- If I comment out the data processing the UIProgressView is visible and updates as expected. With the data processing in place the system seems too bogged down to even display the UIProgressView.
The methods managing the downloads and progress is below.
- (IBAction)downloadNow:(id)sender {
[progressView setHidden:NO];
[progressView setProgress:0.1 animated:YES];
dispatch_sync(backgroundQueue, ^(void){
[self saveRace];
[self updateProgress:0.2];
});
dispatch_sync(backgroundQueue, ^(void){
[self savePositions];
[self updateProgress:0.3];
});
dispatch_sync(backgroundQueue, ^(void){
[self downloadExchanges];
[self saveExchanges];
[self updateProgress:0.4];
});
dispatch_sync(backgroundQueue, ^(void){
[self downloadLegs];
[self saveLegs];
[self updateProgress:0.5];
});
dispatch_sync(backgroundQueue, ^(void){
Utilities *utilities = [[Utilities alloc] init];
[utilities calculateStartTimes:race with:managedObjectContext];
[self updateProgress:1.0];
});
}
(void)updateProgress:(double)completedPercentage {
if (completedPercentage == 1.0) {
[self goHome];
} else if ([importExchanges count] > 0) {
[progressView setProgress:completedPercentage animated:YES];
}
}
Any help is greatly appreciated.
The method dispatch_sync will block the calling thread, which I believe in your case is the main thread. So I think it is better to wrap those dispatch_sync blocks into one dispatch_async block.
As an example:
dispatch_async(backgroundQueue, ^(void){
[self saveRace];
[self updateProgress:0.2];
[self savePositions];
[self updateProgress:0.3];
[self downloadExchanges];
[self saveExchanges];
[self updateProgress:0.4];
[self downloadLegs];
[self saveLegs];
[self updateProgress:0.5];
Utilities *utilities = [[Utilities alloc] init];
[utilities calculateStartTimes:race with:managedObjectContext];
[self updateProgress:1.0];
});
After that you can wrap the updating of the progressView to be done in main thread because it is a UI update.
- (void)updateProgress:(double)completedPercentage {
if (completedPercentage == 1.0) {
[self goHome];
} else if ([importExchanges count] > 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[progressView setProgress:completedPercentage animated:YES];
});
}
}
I'm using CoreData to store objects like cars, trips, data recorded from GPS, etc.
When I fetch what I want to show a list of trips, some stats for a trip, or add a new car in my settings view controller, I use pretty much this kind of request:
- (void)getDataTrip
{
// Fetched data trips.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"DataTrip" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
// Set predicate and sort orderings...
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"timestamp" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"idTrip = %#", self.idTrip];
[fetchRequest setPredicate:predicate];
// Execute the fetch -- create a mutable copy of the result.
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:fetchRequest error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
NSLog(#"failed with error: %#", error);
}
// Set the array.
[self setDataTripArray:mutableFetchResults];
// Memory management.
[fetchRequest release];
[mutableFetchResults release];
}
Sometimes, I have leaks when I do the [self setDataTripArray:mutableFetchResults]; and sometimes not. In this case, when I get the data for a trip, it leaks all the time when I use the navigation controller to come back to the root view controller (displaying a list of trips), and/or when I change tab.
Anyway, it just leaks and it's all the time coming from fetching data from CoreData, and give this array to my local array var.
Please let me know if you see how to fix this! It made the app crash after a while.
Thanks!
SOLUTION
I found that I do a retain on my object dataTripArray object when creating another UIViewController that I use to create graphs for my scroll view.
- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;
// Replace the placeholder if necessary.
GraphController *controller = [self.graphControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[GraphController alloc] initWithPageNumber:page data:[self.dataTripArray retain]];
[self.graphControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// Add the controller's view to the scroll view.
if (controller.view.superview == nil)
{
CGRect frame = _scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[self.scrollView addSubview:controller.view];
}
}
I just removed the retain and the leak is no longer coming up. Fixed!
I have a problem using the -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccesoryControlTapped:(UIControl *)control method. I tried many ways to test it but it just won't appear. Can anyone find a mistake
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)anno{
MKPinAnnotationView *retval=nil;
if(retval ==nil){
retval=[[[MKPinAnnotationView alloc]initWithAnnotation:anno reuseIdentifier:#"Annotations"]autorelease];
UIButton *disclosure=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
retval.rightCalloutAccessoryView=disclosure;
[retval setPinColor:MKPinAnnotationColorGreen];
retval.animatesDrop=YES;
retval.canShowCallout=YES;
}
return retval;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccesoryControlTapped:(UIControl *)control{
NSLog(#"Tap");
PhotoDetail *detail=[[PhotoDetail alloc]initWithNibName:#"PhotoDetail" bundle:nil];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:detail];
[self presentModalViewController:nav animated:YES];
}
Make sure you implemented the
MKMapViewDelegate protocol
in the parent ViewController.