I am trying to load variables into a detail view controller from a NSDictionary in the primary view controller.
I am trying to use the images in the primary view Controller to determine which variable to use in the detail view controller.
My code is like this in the primary View controller;
-(IBAction)pushView:(id) sender{
SomeDetailViewController *detailController = [[SomeDetailViewController alloc] init];
if ((self.imageView.image = [UIImage imageNamed:#"0002.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"titleA", #"headerkey2",,nil];
detailController.mapDictionary = mapDictionary;
NSLog(#"%#", [myDictionary objectForKey:#"headerkey2"]);
}
else if((self.imageView.image = [UIImage imageNamed:#"0003.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"TitleB", #"headerkey2",,nil];
detailController.myDictionary = myDictionary;
NSLog(#"%#", [myDictionary objectForKey:#"headerkey2"]);
}
[self.navigationController pushViewController:detailController animated:YES];
}
then in my receiving detail view controller my code is;
-(void) viewDidLoad{
[super viewDidLoad];
self.title = [(NSMutableDictionary *)myDictionary objectForKey:#"headerkey2"];
}
Unfortunately this is not working. The same thing shows up for the navigationBar title no matter what.
Can I use a UIImage as a condition?
Any help would be greatly appreciated.
I have used the backlash but doesn't seem to be working in all cases.
Do you use "=" in the if statement for some reason? if not, use "==" instead.
the doc says that [UIImage imageNamed] returns the object associated with specified image, which means it should always return the same object for a same image, so you can use UIImage in condition.
Related
i have an big problem with my situation
my main problem is i need fetch video one by one do some operation on the video name and save it to the file system and again fetch another video do some operation on the video name and save it to the file system through the loop of asset the problem is completion handler prevent me do that because it saving all videos together without i do any editing and changing the name this save all videos i think it is working on background thread please any help to fix this problem i need handle fetch video one by one
this is my code
for asset in arrayOfAssets {
if asset.mediaType == .video {
PHImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler: { (AVAsset, AVAudio, info) in
// i need access to this place so i can fetch the video one by one and working with the AVAsset
})
}else{
let imageOp = PHImageRequestOptions()
PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width:125,height:125), contentMode: .aspectFit, options: imageOp, resultHandler: { (img, info) in
print(img!)
})
}
}
i think this one is related to your query
for Vedios
How Can i Get the List of all Video files from Library in ios sdk
for Images
Get all of the pictures from an iPhone photoLibrary in an array using AssetsLibrary framework?
allVideos = [[NSMutableArray alloc] init];
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group)
{
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
dic = [[NSMutableDictionary alloc] init];
ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
NSString *uti = [defaultRepresentation UTI];
NSURL *videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti];
NSString *title = [NSString stringWithFormat:#"video %d", arc4random()%100];
UIImage *image = [self imageFromVideoURL:videoURL];
[dic setValue:image forKey:#"image"];
[dic setValue:title forKey:#"name"];
[dic setValue:videoURL forKey:#"url"];
[`allVideos` addObject:dic];
}
}];
else
{
}
}
failureBlock:^(NSError *error)
{
NSLog(#"error enumerating AssetLibrary groups %#\n", error);
}];
--------for ALL PHOTOS
NSArray *imageArray;
NSMutableArray *mutableArray;
-(void)getAllPhotosFromCamera
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = true;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
NSLog(#"%d",(int)result.count);
PHImageManager *manager = [PHImageManager defaultManager];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];
// assets contains PHAsset objects.
__block UIImage *ima;
for (PHAsset *asset in result) {
// Do something with the asset
[manager requestImageForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info) {
ima = image;
[images addObject:ima];
}];
}
imageArray = [images copy]; // You can direct use NSMutuable Array images
}
Hi Im trying to change the tabcontroller flow, so when a user is not loged in just take him to the login view instead the settings one. My controller extends TabBarController and I set the delegate as
self.tabBarController.delegate=self;
My Code is:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (login) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentViewController:loginViewController animated:YES completion:nil];
return NO;
} else {
return YES;
}
I never manage to do the navigation it gives an excetion :
ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.
I also tried to show the login in as a modal but it only shows a black screen:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (YES) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentModalViewController:navController animated:YES];
return NO;
} else {
return YES;
}
}
Can anybody help Me!!!! please!!!!
Well I manage to fix the black modal screen (still cant d a segue that is not modal).
The problem was that as I am using storyboard I have to load the view from story board as follows.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:#"login"];
[navController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:navController animated:YES];
That made the trick :)
I need to create an app with a Split View but I need to add a tab bar in the Master side of the split, I've read some stuff in this forum but I just can't get it right.
I understand that when you have a split view you actually handle two view controllers the master and the detail so, to my understanding, if I need a tab bar in the master side I have to call the master from the appDelegate and inside this master I can set it up as a Tab Bar controller but either I have a complete misconception or I'm just implementing it wrong.
Here's what I'm doing in the appDelegate, as you can see I'm loading another VC than the master VC that comes with the template, my first question is if I have to load a VC or just an NSObject with the tab bar protocol?:
WTDInitialViewController *initialViewController = [[WTDInitialViewController alloc] initWithNibName:#"WTDInitialViewController" bundle:nil];
UINavigationController *initialNavigationController = [[UINavigationController alloc] initWithRootViewController:initialViewController];
WTDDetailViewController *detailViewController = [[WTDDetailViewController alloc] initWithNibName:#"WTDDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:initialNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
Now, this is what I do in the so called VC
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSMutableArray *vcArray = [[NSMutableArray alloc] initWithCapacity:1];
_tabBarController = [[UITabBarController alloc] init];
WTDMasterViewController *masterViewController = [[WTDMasterViewController alloc] initWithNibName:#"WTDMasterViewController_iPad" bundle:nil];
_navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
_navigationController.navigationBar.barStyle = UIBarStyleBlack;
[vcArray addObject:_navigationController];
_tabBarController.viewControllers = vcArray;
_tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
self.tabBarController.selectedIndex = 0;
[_window addSubview:_tabBarController.view];
[_window makeKeyAndVisible];
}
return self;
It may be a stupid question but I hit a dead end so, any help will be much appreciated
First, I'm assuming you are creating SplitView for ipad. It's initial comes with MasterViewController and DetailViewController. And the MasterViewController is UITableview base, now you want to implement Tabbar base instead, then just call do this in ViewWillAppear of MasterViewController.
UIViewController *viewController1 = [[[YourTabView1 alloc] initWithNibName:#"YourTabView1" bundle:nil]autorelease];
//If you want the view support Navigation then do this
UINavigationController *tab1 = [[[UINavigationController alloc] initWithRootViewController:viewController1]autorelease];
UIViewController *viewController2 = [[[YourTabView2 alloc] initWithNibName:#"YourTabView2" bundle:nil]autorelease];
UINavigationController *tab2 = [[[UINavigationController alloc] initWithRootViewController:viewController2]autorelease];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.viewControllers = [NSArray arrayWithObjects:tab1,tab2,nil];
[self presentModalViewController:tabbarController animated:YES];
I think this should work(but I didnt test the code).
I have added tabbarcontroller, setViewControllers used for providing array of uiviewcontroller. viewDidLoad is called for this viewContollers but not viewDidAppear neither viewWillAppear.
the code I have written
- (void)loadView {
printf("*********\n loadView \n********* ");
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
UITabBarController *tabbar = [[UITabBarController alloc] init];
tabbar.view.frame = CGRectMake(0, 0, 320, 460);
piechartViewController *pr=[[piechartViewController alloc]init];
pr.tagInAction=1;
pr.title=#"Type";
pr.tabBarItem.image=[UIImage imageNamed:#"trend.png"];
pr.sDate=sDate;
pr.nDate=nDate;
piechartViewController *pr1=[[piechartViewController alloc]init];
pr1.title=#"category";
pr1.tagInAction=4;
pr1.sDate=sDate;
pr1.nDate=nDate;
piechartViewController *pr2=[[piechartViewController alloc]init];
pr2.title=#"paidWith";
pr2.tagInAction=3;
pr2.sDate=sDate;
pr2.nDate=nDate;
[tabbar setViewControllers:[NSArray arrayWithObjects:pr,pr1,pr2,nil]];
[self.view addSubview:tabbar.view ];
[pr release];
[pr1 release];
[pr2 release];
}
Hey, are you sure you want to work with loadView and not with viewDidLoad instead?
And might you paste the code when you call this view controller?
Btw, "self.view = contentView"? Probably [self.view addSubview:contentView] sounds better, don't you think?
I'm trying to run a QT Movie located in my application bundle. Can't get it to work. Can someone advise?
thanks.
paul
-(IBAction)runInternalMovie:(id)sender
[
NSString *internalPath;
NSURL *internalURL;
QTMovie *internalMovie;
internalPath = [[NSBundle mainBundle] pathForResource: #"bundledMovie"
ofType: #"mp4"];
internalURL = [NSURL fileURLWithPath: internalPath];
internalMovie = [[QTMovie alloc] initWithURL: internalURL byReference: YES];
}
For one thing, there is no initWithURL:byReference: method. There are many ways to create a QTMovie object, none of which have a byReference: parameter and all of which (except for +movie) take an error: output parameter.
Once you're loading the movie, you need to hand it to a QTMovieView for it to display. The easiest way to create such a view is in IB, by dragging it from the Library panel (QuickTime Kit section) to a window in one of your xibs.
Then, either have an outlet in your controller to the movie view and send the movie view a setMovie: message after creating the movie, or bind the movie view's “Movie” property to a property of your controller.
I always use the initWithFile: method of QTMovie:
NSError* error = nil;
NSString* moviePath = [NSBundle pathForResource:#"bundledMovie" ofType:#"mp4" inDirectory:[[NSBundle mainBundle] bundlePath]];
QTMovie* movie = [QTMovie movieWithFile:moviePath error:&error];
if(movie != nil)
{
[movieView setMovie:movie];
}
else
{
NSLog(#"Error loading movie: %#", [error localizedDescription]);
}
Update:
If you want to use NSURL, use the following:
NSError* error = nil;
QTMovie* movie = [QTMovie movieWithURL:[[NSBundle mainBundle] URLForResource:#"bundledMovie" withExtension:#"mp4"] error:&error];
if(movie != nil)
{
[movieView setMovie:movie];
}
else
{
NSLog(#"Error loading movie: %#", [error localizedDescription]);
}