Clipboard working? - xcode

I have a simple project where I have several NSStrings combined into one. Then, that string is copied to the clipboard. Here is the code:
#import "CopyToClipViewController.h"
#interface CopyToClipViewController ()
#end
#implementation CopyToClipViewController
#synthesize device;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (self.device) {
NSString *namevalue;
NSString *versionvalue;
NSString *companyvalue;
namevalue = [self.device valueForKey:#"name"];
versionvalue = [self.device valueForKey:#"version"];
companyvalue = [self.device valueForKey:#"company"];
NSString *shareString = [NSString stringWithFormat:#"I have performed %# minutes of %# %#",namevalue, versionvalue, companyvalue];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = shareString;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
However, after I build and run the project in the simulator, I can't seem to paste the string into any other app. What is the issue? Thanks in advance!

I think you can paste it only in simulator-open some app with textfield and longpress the textfield. Tap paste

Related

mkmapview not showing according to the frame in nib file

Here is the screen of my nib file and map view but the map is always taking the whole view.I tried resetting my simulator and cleaning my Xcode but nothing works.Am i doing something wrong?
Do i need to give mapview a frame programmatically?
http://prntscr.com/1sy1bw
I also want the button to be on top of mapview if the map cannot be set to take a particular frame.
Consider the below code please:
#import "mapViewController.h"
#interface mapViewController ()
#end
#implementation mapViewController
#synthesize mapView,source,dest,latdest,latsource,longdest,longsource;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
dest=#"delhi";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,160,240)];
CLGeocoder *geocoder1 = [[CLGeocoder alloc] init];
[geocoder1 geocodeAddressString:source
completionHandler:^(NSArray* placemarks, NSError* error)
{
for (CLPlacemark* aPlacemark in placemarks)
{
coordinate.latitude = aPlacemark.location.coordinate.latitude;
latsource=&coordinate.latitude;
coordinate.longitude = aPlacemark.location.coordinate.longitude;
longsource=&coordinate.longitude;
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:(coordinate)];
[annotation setTitle:source];
annotation.subtitle = #"I'm here!!!";
mapView.delegate = self;
[self.mapView addAnnotation:annotation];
}
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,160,240)];
CLGeocoder *geocoder1 = [[CLGeocoder alloc] init];
[geocoder1 geocodeAddressString:source
completionHandler:^(NSArray* placemarks, NSError* error)
{
for (CLPlacemark* aPlacemark in placemarks)
{
coordinate.latitude = aPlacemark.location.coordinate.latitude;
latsource=&coordinate.latitude;
coordinate.longitude = aPlacemark.location.coordinate.longitude;
longsource=&coordinate.longitude;
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:(coordinate)];
[annotation setTitle:source];
annotation.subtitle = #"I'm here!!!";
[self.view addSubview:mapView];
[self.mapView addAnnotation:annotation];
}
}];
}
I commented the mapview alloc codeline and this fixed the issue.Seems like mapview gets pushed as soon as its allocated memory space.Moreover the frame coordinated that i initialised mapviewview with are still preserved although the code is commented.Dont know if it should work this way only or not but it did solved my issue .

Perform segue with accessoryButton

I am doing master + detail pages. I have successfully made tapping the cell rows in the master page jump to detail page, using the code below
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"MasterToDetail" sender:indexPath];
}
However becuase my master page cell rows also have accessory buttons, i need to make these buttons able to jump to the detail page too through tapping. So i implemented code
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"MasterToDetail" sender:self];
}
Howver the details dispalyed is not correct. It always shows the first detail data in the datalist. I changed sender:self to sender:indexPath also no working.
I used stackoverflow answers from here and here. I am a beginner, so some concepts still no clear sorry.
Edited
- preparesegue for masterviewcontroller.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
DetailViewController *detailController =segue.destinationViewController;
SearchDataDetail *bug = [self.bugs objectAtIndex:self.tableView.indexPathForSelectedRow.row];
detailController.detailItem = bug;
}
-detailviewcontroller.m
#import "DetailViewController.h"
#import "SearchData.h"
#import "SearchDataDetail.h"
#interface DetailViewController ()
- (void)configureView;
#end
#implementation DetailViewController
- (void)configureView
{
// Update the user interface for the detail item.
self.rateView.notSelectedImage = [UIImage imageNamed:#"shockedface2_empty.png"];
self.rateView.halfSelectedImage = [UIImage imageNamed:#"shockedface2_half.png"];
self.rateView.fullSelectedImage = [UIImage imageNamed:#"shockedface2_full.png"];
self.rateView.editable = YES;
self.rateView.maxRating = 5;
self.rateView.delegate = self;
if (self.detailItem) {
self.titleField.text = self.detailItem.data.title;
self.rateView.rating = self.detailItem.data.rating;
self.imageView.image = self.detailItem.fullImage;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self configureView];
}
- (void)viewDidUnload
{
[self setTitleField:nil];
[self setRateView:nil];
[self setImageView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)rateView:(RateView *)rateView ratingDidChange:(float)rating {
self.detailItem.data.rating = rating;
}
#end
This is due to following statement
SearchDataDetail *bug = [self.bugs objectAtIndex:self.tableView.indexPathForSelectedRow.row];
In this self.tableView.indexPathForSelectedRow.row will work only for only for row selection
not for accessoryButton tap.
You can solve it by two easy way
Declare a variable in .h file to store indexPath and use it to pass selected indexPath.
Pass indexPath in sender
All the best..

Warning: Attempt to present <MachinesDetailViewController: 0x1e5bfc50> on <UITabBarController: 0x1f867d90> whose view is not in the window hierarchy

Im trying to get a scanned QR code to display a view controller with information about the item the code represents. When I try and segue to the detail view controller, it comes up with:
Warning: Attempt to present <MachinesDetailViewController: 0x1e5bfc50> on <UITabBarController: 0x1f867d90> whose view is not in the window hierarchy!
The MainViewController is withing a main tab bar controller, but the detail view controller is within a navigation controller which is withing the tab bar controller.
Heres my MainViewController.m where this is sitting.
//
// FirstViewController.m
// Fitness Plus+
//
// Created by Tom Brereton on 26/01/13.
// Copyright (c) 2013 Tom Brereton. All rights reserved.
//
#import "MainViewController.h"
#import "MachinesDetailViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize resultText, machineKeys, codeInt, machineArea, machineName;
- (IBAction)scanButton:(id)sender {
NSLog(#"ehe");
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
NSLog(#"Got here");
// present and release the controller
[self presentViewController: reader
animated: YES
completion:nil];
}
- (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;
NSLog(#"Naht Here");
// EXAMPLE: do something useful with the barcode data
// Scan the machines.plist array and print it to the console.
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"machines" ofType:#"plist"];
NSDictionary *machineDict = [NSDictionary dictionaryWithContentsOfFile:filePath];
machineKeys = [machineDict objectForKey:#"Exercises"];
machineArea = [machineDict objectForKey:#"Area"];
resultText.text = symbol.data;
//Convert code into integer value and put it inside codeInt
codeInt = [symbol.data intValue];
NSLog(#"Scanned Value: %#", [machineKeys objectAtIndex:codeInt]);
// EXAMPLE: do something useful with the barcode image
[self performSegueWithIdentifier:#"showDetailFromMain" sender:reader];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)reader {
if ([[segue identifier] isEqualToString:#"showDetailFromMain"]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MachinesDetailViewController *machineViewController = [storyboard instantiateViewControllerWithIdentifier:#"showMachineDetailViewController"];
machineViewController = [segue destinationViewController];
machineName = [machineKeys objectAtIndex:codeInt];
[machineViewController setMachineNameLabel: machineName];
}
}
- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The ZBar stuff is just relating to the QR scanning API.
And here is the MachineDetailsViewController.m.
//
// MachinesDetailViewController.m
// Fitness Plus+
//
// Created by Tom Brereton on 27/01/13.
// Copyright (c) 2013 Tom Brereton. All rights reserved.
//
#import "MachinesDetailViewController.h"
#interface MachinesDetailViewController ()
#property(nonatomic, copy) NSString *title;
#end
#implementation MachinesDetailViewController
#synthesize machineLabel, machineName, instructionsLabel, typeLabel, mainMuscleLabel, otherMuscleLabel, equipmentLabel, machineDictionary, machineArray, mainMuscleLabelString, instructionLabelString, typeLabelString, otherMuscleLabelString, equipmentLabelString, title, machineNameLabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Set the Label text with the selected machine name
machineName = machineNameLabel;
mainMuscleLabel.text = mainMuscleLabelString;
otherMuscleLabel.text = otherMuscleLabelString;
equipmentLabel.text = equipmentLabelString;
typeLabel.text = typeLabelString;
instructionsLabel.text = instructionLabelString;
self.navigationItem.title = machineName;
NSLog(#"got it");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Thanks, if you need more info just ask.
Tom
Struggled with the exact same issue,
my solution was to call the segue this way:
[reader dismissViewControllerAnimated:YES completion:^{
NSLog(#"Perform segue");
[self performSegueWithIdentifier:#"showDetailFromMain" sender:self];
}];
I also had to connect the segue to the view and not to a single button.
Hope this works for you.

Building Ipad app and once i added a modal view my bool errors out

I am erroring out with Bool and before I added a modal view and now it says bool is undefined. I dont understand why that is unless its because I'm using another nib for my modal view.
Do I need to call or change my boon now. Please advise.
//
// UrbanAgentViewController.m
// UrbanAgent
//
// Created by Dwayne Stephens on 4/2/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "UrbanAgentViewController.h"
#import "NewContactController.h"
#implementation UrbanAgentViewController
// our own buttonTapped method
-(IBAction) buttonTapped: (id) sender {
NewContactController *ivc = [[NewContactController alloc] init];
ivc.delegate = self;
UINavigationController *nc = [[UINavigationController alloc]
initWithRootViewController:ivc];
[self presentModalViewController:nc animated:YES];
[ivc release];
[nc release];
}
-(void) doneButtonPressed: (NSArray *) values
{
[self dismissModalViewControllerAnimated:YES];
NSString *message =
[[NSString alloc]
initWithFormat:#"The values were %#, %#, %#, %#, %#, and %#",
[values objectAtIndex:0], [values objectAtIndex:1], [values objectAtIndex:2],
[values objectAtIndex:3], [values objectAtIndex:4], [values objectAtIndex:5]];
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:#"Values Passed"
message:message delegate:nil
cancelButtonTitle:#"Excellent!" otherButtonTitles:nil ];
[alert show];
[alert release];
[message release];
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
You need a closing curly brace on doneButtonPressed:.

Need help debugging switchChanged method

Am getting error ("switchChanged" undeclared) in the implementation file, but can't find the problem. Can you help me?
TIA
ViewController.m
#import "Control_FunViewController.h"
#implementation Control_FunViewController
#synthesize nameField;
#synthesize numberField;
#synthesize sliderLabel;
#synthesize leftSwitch;
#synthesize rightSwitch;
#synthesize doSomethingButton;
-(IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)(slider.value + 0.5f);
NSString *newText = [[NSString alloc] initWithFormat:#"%d",progressAsInt];
sliderLabel.text = newText;
[newText release];
}
-(IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)backgroundTap:(id)sender
{
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
-(IBAction)toggleControls:(id)sender
{
if ([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
leftSwitch.hidden = NO;
rightSwitch.hidden = NO;
doSomethingButton.hidden = YES;
}
else {
leftSwitch.hidden =YES;
rightSwitch.hidden =YES;
doSomethingButton.hidden = NO;
}
-(IBAction)switchChanged:(id)sender
{
UISwitch *whichSwitch = (UISwitch *)sender;
BOOL setting = whichSwitch.isOn;
[leftSwitch setOn:setting animated:YES];
[rightSwitch setOn:setting animated:YES];
}
-(IBAction)buttonPressed
{
//TODO: Implement Action Sheet and Alert
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[nameField release];
[numberField release];
[sliderLabel release];
[leftSwitch release];
[rightSwitch release];
[doSomethingButton release];
[super dealloc];
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#define kSwitchesSegmentIndex 0
#interface Control_FunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
UILabel *sliderLabel;
UISwitch *leftSwitch;
UISwitch *rightSwitch;
UIButton *doSomethingButton;
}
#property(nonatomic,retain)IBOutlet UITextField *nameField;
#property(nonatomic,retain)IBOutlet UITextField *numberField;
#property(nonatomic,retain)IBOutlet UILabel *sliderLabel;
#property(nonatomic,retain)IBOutlet UISwitch *leftSwitch;
#property(nonatomic,retain)IBOutlet UISwitch *rightSwitch;
#property(nonatomic,retain)IBOutlet UIButton *doSomethingButton;
-(IBAction)textFieldDoneEditing:(id)sender;
-(IBAction)backgroundTap:(id)sender;
-(IBAction)sliderChanged:(id)sender;
-(IBAction)toggleControls:(id)sender;
-(IBAction)switchChanged:(id)sender;
-(IBAction)buttonPressed;
#end
The colon (:) is part of the name of the method, but you haven't included it in the error message. It may be that you just forgot, but if you're calling -switchChanged (no colon) from somewhere, or if you connected a control using the action -switchChanged (no colon), that's the problem. Perhaps you added the colon and sender parameter later on?

Resources