I have a mainViewController which pushes a detailViewController onto the screen.
The items (images, navigation bar title, textview, and a button) in the detailViewController are all loaded from an NSMutableDictionary in the MainViewController depending on which image in it is tapped.
I also have a button in the detailViewController that when selected loads a mapview which shows the user's location. When the user taps a button a pin is dropped marking this location with a annotation callout title.
I want the title of the mapview and the annotation title to be the same as the detailViewController's which is loaded from the MainViewController's NSMutableDictionary.
Right now I am trying to use the detailViewController's title as the determining factor in the mapview's title and annotation title. However this isn't working.
Here is my code in MainViewController .m.
- (void) coverflowView:(TKCoverflowView*)coverflowView coverAtIndexWasDoubleTapped:(int)index{
SomeDetailViewController *detailViewController = [[SomeDetailViewController alloc] initWithNibName:#"SomeDetailViewController" bundle:nil];
if ((int)index == 0) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"0002.jpg", #"imagekey",
#"This is tree 0002", #"textkey",
#"0002.image.png",#"imagekey2",
#"0002 title", #"headerkey",
#"www.0003.com", #"address",nil];
NSLog(#"%#", [myDictionary objectForKey:#"imagekey"]);
NSLog(#"%#", [myDictionary objectForKey:#"textkey"]);
NSLog(#"%#", [myDictionary objectForKey:#"imagekey2"]);
NSLog(#"%#", [myDictionary objectForKey:#"address"]);
NSLog(#"%#", [myDictionary objectForKey:#"headerkey"]);
detailViewController.myDictionary = myDictionary;
}
else if ((int)index == 1) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"0003.jpg", #"imagekey",
#"This is 0003", #"textkey",
#"0003.image.png",#"imagekey2",
#"0003 title", #"headerkey",
#"www.0003.com", #"address",nil];
NSLog(#"%#", [myDictionary objectForKey:#"imagekey"]);
NSLog(#"%#", [myDictionary objectForKey:#"textkey"]);
NSLog(#"%#", [myDictionary objectForKey:#"imagekey2"]);
NSLog(#"%#", [myDictionary objectForKey:#"address"]);
NSLog(#"%#", [myDictionary objectForKey:#"headerkey"]);
detailViewController.myDictionary = myDictionary;
}
[self.navigationController pushViewController:detailViewController animated:YES];
}
Here is my code in the detailViewController.m.
This loads my Dictionary strings (The bold part is loading the navigation bar title).
- (void)viewDidLoad {
NSString *filePath =[self pathOfFile];
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]){
NSArray *array = [[NSArray alloc]initWithContentsOfFile:filePath];
myText.text = [array objectAtIndex:0];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
[super viewDidLoad];
imageView .image = [[UIImage alloc] init];
self.imageView.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:#"imagekey"]];
imageView2 .image = [[UIImage alloc] init];
self.imageView2.image =[UIImage imageNamed:[(NSMutableDictionary *)myDictionary objectForKey:#"imagekey2"]];
self.myText.text =[(NSMutableDictionary *)myDictionary objectForKey:#"textkey"];
**self.navigationItem.title = [(NSMutableDictionary *)myDictionary objectForKey:#"headerkey"];**
NSLog(#"%#", [myDictionary objectForKey:#"imagekey"]);
NSLog(#"%#", [myDictionary objectForKey:#"imagekey2"]);
NSLog(#"%#", [myDictionary objectForKey:#"textkey"]);
NSLog(#"%#", [myDictionary objectForKey:#"headerkey"]);
}
Here is where I am trying to load the navigation bar title and annotation title using the current navigation bar title as the determining factor.
This is the only thing I can think of to use since there is no stable element. Everything in the detailViewController is loaded from the MainViewController NSDictionary.
-(IBAction)pushMap:(id) sender{
SomePositionViewController *somePosition = [[SomePositionViewController alloc] init];
if ((self.navigationItem.title = #"0002 title")) {
NSMutableDictionary *mapDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"0002a title", #"headerkey2",
#"0002 annotation title", #"titlekey",nil];
treePosition.mapDictionary = mapDictionary;
NSLog(#"%#", [mapDictionary objectForKey:#"titlekey"]);
NSLog(#"%#", [mapDictionary objectForKey:#"headerkey2"]);
}
else if((self.navigationItem.title = #"0003 title")) {
NSMutableDictionary *mapDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"0003a title", #"headerkey2",
#"0003 annotation title", #"titlekey",nil];
treePosition.mapDictionary = mapDictionary;
NSLog(#"%#", [mapDictionary objectForKey:#"titlekey"]);
NSLog(#"%#", [mapDictionary objectForKey:#"headerkey2"]);
}
[self.navigationController pushViewController:somePosition animated:YES];
}
Does anyone have any idea how I can accomplish this? I have been wracking my brain but to no avail. HELP!
One thing I spotted is that you are comparing strings the wrong way. You use
if ((self.navigationItem.title = #"0002 title"))
but should use
if (([self.navigationItem.title isEqualToString:#"0002 title"]))
Comparing strings in your way will always fail.
Related
How can I use activity indicator in second view controller to let data to be complete load
first VC
- (IBAction)btnOpenHTML:(id)sender {
RecievVC *obj = [self.storyboard instantiateViewControllerWithIdentifier:#"RecievVC"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:lblName.text forKey:#"lblname"];
//........Lots of Data........(then in the end of 1st VC)........//
obj.dicData = dict;
[self.navigationController pushViewController:obj animated:true];
}
#end
the 2nd VC Code after viewdidload
- (void)viewDidLoad {
[super viewDidLoad];
[self->webView.scrollView setScrollEnabled:true];
[self->webView loadHTMLString:[self getHTMLStirng] baseURL:[NSURL URLWithString:#""]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(NSString *)getHTMLStirng {
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"resumeT" ofType:#"html"];
NSString *strHTML = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
if (self.dicData) {
strHTML = [strHTML stringByReplacingOccurrencesOfString:#"#NAME" withString:[_dicData valueForKey:#"lblname"]];
//...............Lots of Data......Then at the end of 2nd VC............//
}return strHTML;
}
what I main by lots of data, it's around 150 of keys and value have to be send from 1st VC to 2nd VC.
any idea?
You could try GCD:
// instantiate the activity indicator
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray];
activity.center = self.view.center;
// start your activity indicator
[activity startAnimating]
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// load data on background thread
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:lblName.text forKey:#"lblname"];
//........Lots of Data........(then in the end of 1st VC)........//
// update UI on main thread
dispatch_async(dispatch_get_main_queue(), ^{
// stop your activity indicator
[activity stopAnimating]
RecievVC *obj = [self.storyboard instantiateViewControllerWithIdentifier:#"RecievVC"];
obj.dicData = dict;
[self.navigationController pushViewController:obj animated:true];
});
});
I'm having a tableview. And in my didselectrow I get the right object that I want to pass to the next controller.
This is my code:
id<NavigateDelegate> strongDelegate = self.delegate;
NSDictionary * dictionary = [_dataArray objectAtIndex:indexPath.section];
NSArray * array = [dictionary objectForKey:#"data"];
POI * poi = [array objectAtIndex:indexPath.row];
NSLog(#"%#", poi);
NSLog(#"Category %#", poi.rank.name);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailsViewController * detailsController = [[DetailsViewController alloc] init];
detailsController.details = [[NSDictionary alloc] initWithObjectsAndKeys:poi.name, #"name", poi.address, #"address", poi.details, #"details", poi.title, #"title", poi.url, #"url", nil];
if ([strongDelegate respondsToSelector:#selector(navigateFromTo:to:)]) {
[strongDelegate navigateFromTo:self to:detailsController];
}
Then in my delegate receiver I push the controller like:
- (void) navigateFromTo:(POITableViewController *)viewController to:(UIViewController *)toController
{
[self.navigationController pushViewController:toController animated:YES];
}
But still my DetailsController his details NSdictionary is null.
What am I doing wrong?
I found the problem. The viewdid load is called before my setter is called.
So I changed the init method like this:
-(instancetype) initWithPoi:(NSDictionary *) poi
{
self = [super init];
if(self)
{
NSLog(#"Init DetailsViewController");
_details = poi;
[self initializeViews];
}
return self;
}
that way the controller has the poi details from the start.
I am using tab bar in my iOS app. When I tap on the scan tab, i invoked the delegate method to start the camera immediately on scan tab. When I start the camera to scan the QR Code and tap on cancel button before scanning, I get the blank view. How to display the view when camera is dismissed
- (void) openCameraScanner
{
ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = YES;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentViewController:reader animated:YES completion:nil];
reader.showsZBarControls = YES;
//reader.cameraOverlayView = [self commonOverlay];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
//resultsView.text = symbol.data;
NSString *urlString = symbol.data;
NSURL *url = [NSURL URLWithString:urlString];
NSLog(#"Query after scan = %#", [url query]);
//Extract id from URL which is there in QR Code --- start
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
for(NSString *param in [urlString componentsSeparatedByString:#"&"])
{
NSArray *elements = [param componentsSeparatedByString:#"="];
if([elements count]<2)
continue;
[dictionary setObject:[elements objectAtIndex:1] forKey:[elements objectAtIndex:0]];
NSLog(#"value is == %#", [elements objectAtIndex:1]);
//Extract id from URL which is there in QR Code --- end
if([[elements objectAtIndex:1] intValue])
{
NSUserDefaults *defaultsForAsk = [NSUserDefaults standardUserDefaults];
idToAsk = [NSString stringWithFormat:#"%d",[[elements objectAtIndex:1] intValue]];
[defaultsForAsk setObject:idToAsk forKey:#"IDTOASKVIEW"];
flagToShowView = YES;
listViewCntrl.getFlag = flagToShowView;
[self viewDidLoadForDynamicFields];
}
else if([elements objectAtIndex:1] == [NSNull null])
{
[reader dismissViewControllerAnimated:YES completion:Nil];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Invalid QR Code scanned" message:#"Please scan Collaborator's QR Code" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[message show];
}
}
image.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
//[reader dismissViewControllerAnimated:YES completion:nil];
[reader dismissViewControllerAnimated:YES completion:Nil];
}
You can re display the view using -(void)viewWillAppear:(BOOL)animated method of your ViewController class.
Hi I have a grouped tableview the first section contains a list of emails and the second section just has two rows which are add email manually and select email from contacts.
The log in ManualEmail.m keeps logging 0 for the count and the array in EmailViewController is never modified, but I can't figure out what's wrong
This is my current set up
EmailViewController.h
#property (nonatomic, retain) IBOutlet NSMutableArray *dataArray;
EmailViewController.m
#synthesize dataArray;
- (void)viewDidLoad {
[super viewDidLoad];
dataArray = [[NSMutableArray alloc] init];
NSMutableArray *listItems = [[NSMutableArray alloc] initWithObjects:nil];
[listItems addObject:[ObjectArrays productWithType:#"test" Eemail:#"test#website.com" Eselected:YES]];
NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:listItems forKey:#"data"];
[dataArray addObject:firstItemsArrayDict];
NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:#"Add Email Address From Contacts", #"Add Email Address Manually", nil];
NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:#"data"];
[dataArray addObject:secondItemsArrayDict];
[tableView reloadData];
}
ManualEmail.m
EmailViewController *emailPVC = [[EmailViewController alloc] init];
NSDictionary *dictionary = [emailPVC.dataArray objectAtIndex:0];
NSArray *array = [dictionary objectForKey:#"data"];
NSMutableArray *emailArray = [NSMutableArray arrayWithArray:array];
[emailArray addObject:[ObjectArrays productWithType:name.text Eemail:email.text Eselected:YES]];
[emailPVC.dataArray removeObjectAtIndex:0];
NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:emailArray forKey:#"data"];
[emailPVC.dataArray insertObject:firstItemsArrayDict atIndex:0];
NSLog(#"%d", [emailPVC.dataArray count]);
In ManualEmail.m, you're creating the EmailViewController in code. But you aren't ever calling anything that would call its -viewDidLoad method, so the dataArray isn't ever getting created or filled out. You need to call emailPVC.view = <some view you created>; in order for -viewDidLoad to get called.
I need one button called email button to do one selection from multiple item from picker view to attach that selected item via email. I am stuck at the IBAction. Here is my progress.
M File :
-(void)pickerViewEmail:(UIPickerView *)pickerViewEmail didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if ([[musicList objectAtIndex:row] isEqual:#"m1"])
{
MFMailComposeViewController *pickerEmail = [[MFMailComposeViewController alloc] init];
pickerEmail.mailComposeDelegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:#"m1" ofType:#"mp3"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[pickerEmail addAttachmentData:myData mimeType:#"audio/mp3" fileName:#"m1"];
[pickerEmail setSubject:#"Hello!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"first#example.com"];
NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:#"fourth#example.com"];
[pickerEmail setToRecipients:toRecipients];
[pickerEmail setCcRecipients:ccRecipients];
[pickerEmail setBccRecipients:bccRecipients];
// Fill out the email body text
NSString *emailBody = #"Hello";
[pickerEmail setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:pickerEmail animated:YES];
[pickerEmail release];
}
if ([[musicList objectAtIndex:row] isEqual:#"m2"])
{
}
if ([[musicList objectAtIndex:row] isEqual:#"m3"])
{
}
IBAction :
-(IBAction)showEmail
{
if ([MFMailComposeViewController canSendMail])
{
[self pickerEmail]; I have a yellow error when i call this. What is the right solution?
}
else
{
}
}
iOS : How to attach a multiple attachment file in one button using pickerview method?
I don't understand your call [self pickerEmail]
Higher in your code, pickerEmail seems to be an object, of type MFMailComposeViewController, not a method. So the call [self pickerEmail] does not have any sense in Objective-C