IBAction Method not being called when button is pushed. But View controller is being pushed - objective-c

I am attempting to pass information from one viewController to another using a push segue with an IBAction button named *line. However from what I can tell this method is not being called and the NSLog(#"%#", see); I inserted to test the method is not displaying any message. Here is some code for the first viewController.
DetailController.m
#import "DetailController.h"
#import "City.h"
#import "ViewController.h"
#import "VideoController.h"
#import "Helper.h"
#interface DetailController ()
#property (nonatomic, strong) IBOutlet VideoController *videoViewController;
#end
#implementation DetailController
#synthesize city, ClubName, Price, Vip, Promo, remain,p,deal,money,camera,tweet,post;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.videoViewController = [[VideoController alloc] init];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320,1400)];
[super viewDidLoad];
UIImage *highlightedButtonImage = [UIImage imageNamed:#"twitter.png"];
UIImage *highlightedButtonImage2 = [UIImage imageNamed:#"twitter2.png"];
[Helper customizeBarButton:self.tweet image:highlightedButtonImage highlightedImage:highlightedButtonImage2];
UIImage *faceButtonImage = [UIImage imageNamed:#"facebook.png"];
UIImage *faceButtonImage2 = [UIImage imageNamed:#"facebook2.png"];
[Helper customizeBarButton:self.post image:faceButtonImage highlightedImage:faceButtonImage2];
UIImage *taxiButtonImage = [UIImage imageNamed:#"taxi.png"];
UIImage *taxiButtonImage2 = [UIImage imageNamed:#"taxi2.png"];
[Helper customizeBarButton:self.taxi image:taxiButtonImage highlightedImage:taxiButtonImage2];
// Do any additional setup after loading the view.
UIFont *labelFont=[UIFont fontWithName:#"King Kikapu" size:15.0];
UIFont *myFont=[UIFont fontWithName:#"Deutsch Gothic" size:20.0];
UIFont *myFont2=[UIFont fontWithName:#"Deutsch Gothic" size:35.0];
UIFont *titleFont=[UIFont fontWithName:#"Pornstar" size:50.0];
NSString * name= self.city.clubName;
NSString * line= self.city.clubLine;
NSString * description= self.city.promo;
NSString * price= self.city.price;
NSString *ipCam= self.city.camera;
remain.font=labelFont;
remain.text=#"VIP Remaining :";
p.font=labelFont;
p.text=#"Price :";
money.font=myFont;
deal.font=labelFont;
deal.text=#"Promotions :";
ClubName.font=titleFont;
ClubName.text=name;
Vip.font=myFont2;
Vip.text=line;
Price.font=myFont2;
Price.text=price;
Promo.font=myFont;
Promo.text=description;
}
- (IBAction)PostFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController * facebook= [[SLComposeViewController alloc]init];
facebook= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[NSString stringWithFormat:#"I'm heading to"]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result){
NSString * output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output=#"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output=#"Post Succesful";
default:
break;
}
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}];
}}
- (IBAction)PostTwitter:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"I'm heading to"];
[self presentViewController: tweetSheet animated:YES completion:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)line:(id)sender {
NSString *see=self.city.camera;
NSLog(#"%#", see);
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil];
self.videoViewController = [storyboard instantiateViewControllerWithIdentifier:#"Page3"];
self.videoViewController.city.camera= self.city.camera;
[self.navigationController pushViewController:self.videoViewController animated:YES];
}
#end
As a test I inserted NSLog(#"%#", see); into the IBAction method but this is not returning any value
DetailController.h
#import <UIKit/UIKit.h>
#import "VideoController.h"
#import <Social/Social.h>
#class City;
#interface DetailController : UIViewController {
IBOutlet UIScrollView *scroller;
}
#property (weak, nonatomic) IBOutlet UIBarButtonItem *taxi;
#property (strong,nonatomic) City *city;
#property (weak, nonatomic) IBOutlet UILabel *ClubName;
#property (weak, nonatomic) IBOutlet UILabel *Vip;
#property (weak, nonatomic) IBOutlet UILabel *Price;
#property (nonatomic, strong)NSString * camera;
#property (weak, nonatomic) IBOutlet UILabel *Promo;
#property (weak, nonatomic) IBOutlet UILabel *remain;
#property (weak, nonatomic) IBOutlet UILabel *p;
#property (weak, nonatomic) IBOutlet UILabel *deal;
#property (weak, nonatomic) IBOutlet UILabel *money;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *tweet;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *post;
- (IBAction)line:(id)sender;
#end
Thanks for any suggestions on why this method is not being called when the button is pushed

The only way for your IBAction to NOT get called is when the button is not appropriately connected to it. Double check that in the connections inspector.

Related

Passing map-data between ViewController

I nearly followed this post. The viewcontroller will push via storyboard. Here the relevant code:
ViewController.m:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
MapPoint.h:
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_title;
NSString *_subtitle;
CLLocationCoordinate2D _coordinate;
UIImage *_storeImage;
}
#property (copy) NSString *title;
#property (copy) NSString *subtitle;
#property (nonatomic, readonly) UIImage *storeImage;
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle coordinate:(CLLocationCoordinate2D)coordinate storeImage:(UIImage*)storeImage;
and DetailViewController:
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
I think my mistake is in the calloutAccessoryControlTapped method but I dont know what is the real reason for this issue.
If you use a storyboard, can use prepareForSegue method and set within a class similarly as you have made.
I post a portion of code
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"Brs"]){
NSLog(#"segue %# ",[segue identifier]);
[segue.destinationViewController setPath:[ris_xml objectAtIndex:index_post-1] ];
}
}
In this example I set attribute "Path" of next UIViewController only if his identifier is "Brs".
For use this method is need set UIviewController identifier into storyboard right panel.
Using this isn't need to instantiate new UIViewController if you have it in storyboard.
I solved it by thinking about loading sequence.
All what to do is create temporary #properties
#interface DetailViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *branchImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UITextView *textView;
#property (nonatomic) NSString *titleTMP; //added
#property (nonatomic) NSString *subtitleTMP; //added
and do
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(#"%#", view.annotation.title);
MapPoint *annView = view.annotation;
DetailViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
dvc.title = #"my own Details";
dvc.titleTMP = annView.title;
dvc.subtitleTMP = annView.subtitle;
[self.navigationController pushViewController:dvc animated:YES];
}
The DetailViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
titleLabel.text = titleTMP;
textView.text = subtitleTMP;
}

How to save UIImages in view

In my app I have two views: a mapView, and a detail view. The mapView has annotations, and the annotation views have right callout buttons that push the detail view onto the stack when the callout button is pressed. In the detail view, the user can take a picture that appears on the UIImage that is on the detail view controller. What I want is for a different image to be on the detail view controller for each annotation. I have read that I can use a singleton, and I have made a singleton class, but I do not know how to use it. Can someone help me out?
Here is some code:
My MKAnnotation class:
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_address;
CLLocationCoordinate2D _coordinate;
NSNumber *_identifier;
UIImage *_image;
}
- (id)initWithAddress:(NSString*)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident;
//This is a required property from MKAnnotation
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
//This is an optional property from MKAnnotataion
#property (nonatomic, copy) NSString *title;
#property (nonatomic, readonly, copy) NSString *subtitle;
#property (nonatomic) BOOL animatesDrop;
#property (nonatomic) BOOL canShowCallout;
#property (copy) NSString *address;
#property (copy) NSNumber *identifier;
#property (copy,nonatomic) UIImage *image;
#end
#implementation MapPoint
#synthesize title, subtitle, animatesDrop, canShowCallout;
#synthesize address = _address, coordinate = _coordinate, identifier = _identifier, image = _image;
-(id)initWithAddress:(NSString *)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident
{
self = [super init];
if (self) {
_address = [address copy];
_coordinate = coordinate;
_identifier = ident;
[self setTitle:t];
NSDate *theDate = [NSDate date];
subtitle = [NSDateFormatter localizedStringFromDate:theDate
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterMediumStyle];
}
return self;
}
#end
Here is the detail view controller:
#import <UIKit/UIKit.h>
#class P2OViewController;
#interface PinViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate>
{
__weak IBOutlet UILabel *label;
__weak IBOutlet UIButton *removeButton;
NSString *addressForLabel;
__weak P2OViewController *_vc;
__weak NSNumber *_identifier;
}
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UIButton *removeButton;
#property (weak, nonatomic) P2OViewController *vc;
#property (weak, nonatomic) NSNumber *identifier;
-(void)takePicture:(id)sender;
-(void)buttonPressed:(id)sender;
#end
#import "PinViewController.h"
#import "MapPoint.h"
#import "P2OViewController.h"
#implementation PinViewController
#synthesize imageView, label, removeButton;
#synthesize vc = _vc, identifier = _identifier;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIBarButtonItem *pic = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:#selector(takePicture:)];
[[self navigationItem]setRightBarButtonItem:pic];
}
return self;
}
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
//If our device has a camera, we ant to take a picture, otherwise, we just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
//Place the image picker on the screen
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//Put the image onto the screen in out image view
[imageView setImage:image];
//Take image picker off the screen - you must call this dismiss method
[self dismissViewControllerAnimated:YES
completion:nil];
}
#end
You surely have a class implementing the MKAnnotation protocol.
In this class simply add a UIImage property and assign to every annotation its custom image.
Then when presenting the detailed view you just pass around the annotation and access its image property you defined.
EDIT
In your PinViewController simply declare a property like this
#property(nonatomic, strong) MapPoint * annotation;
Before you present your PinViewController assign the corresponding annotation to it, doing something like
detailedController.annotation = theAnnotation;
Do whatever you need to do to get the image, then store it in the annotation in this way
self.annotation.image = theImage;
Now the annotation is storing the image, so as long as you keep it in memory it will be there available for you.
The next time you push the detailed view you can perform a check to see whether that annotation has already an image or not
if(nil != self.annotation.image) {
// do something
} else {
// do something else
}

Having trouble declaring/initializing array of CGPoints

Like most of my problems recently, i think it's a syntax problem. I know what i want to do but i don't know how to write it. I am trying to create a Jigsaw-type application. The CGPoints represent the center point of where each image should be.
I have created 40 images and put them into an array.
I want to create 40 CGPoints and put all these points in an array.
The image at images[0] has a corresponding center at cgpoints[0] - or rather this is where the image should be placed in the jigsaw.
I'm having trouble declaring/initializing the array of CGPoints though. Below is the code:
.h file
#import <UIKit/UIKit.h>
#interface DSAAssignmentViewController2 : UIViewController
#property (weak, nonatomic) NSString *passedData;
#property (weak, nonatomic) IBOutlet UILabel *lblDisplayPreviousInput;
#property (weak, nonatomic) IBOutlet UIImageView *imgOriginal;
#property (weak, nonatomic) IBOutlet UIImageView *img1;
#property (weak, nonatomic) IBOutlet UIImageView *img2;
#property (weak, nonatomic) IBOutlet UIImageView *img3;
#property (weak, nonatomic) IBOutlet UIImageView *img4;
#property (weak, nonatomic) IBOutlet UIImageView *img5;
#property (weak, nonatomic) IBOutlet UIImageView *img6;
#property (weak, nonatomic) IBOutlet UIImageView *img7;
#property (weak, nonatomic) IBOutlet UIImageView *img8;
#property (weak, nonatomic) IBOutlet UIImageView *img9;
#property (weak, nonatomic) IBOutlet UIImageView *img10;
#property (weak, nonatomic) IBOutlet UIImageView *img11;
#property (weak, nonatomic) IBOutlet UIImageView *img12;
#property (weak, nonatomic) IBOutlet UIImageView *img13;
#property (weak, nonatomic) IBOutlet UIImageView *img14;
#property (weak, nonatomic) IBOutlet UIImageView *img15;
#property (weak, nonatomic) IBOutlet UIImageView *img16;
#property (weak, nonatomic) IBOutlet UIImageView *img17;
#property (weak, nonatomic) IBOutlet UIImageView *img18;
#property (weak, nonatomic) IBOutlet UIImageView *img19;
#property (weak, nonatomic) IBOutlet UIImageView *img20;
#property (weak, nonatomic) IBOutlet UIImageView *img21;
#property (weak, nonatomic) IBOutlet UIImageView *img22;
#property (weak, nonatomic) IBOutlet UIImageView *img23;
#property (weak, nonatomic) IBOutlet UIImageView *img24;
#property (weak, nonatomic) IBOutlet UIImageView *img25;
#property (weak, nonatomic) IBOutlet UIImageView *img26;
#property (weak, nonatomic) IBOutlet UIImageView *img27;
#property (weak, nonatomic) IBOutlet UIImageView *img28;
#property (weak, nonatomic) IBOutlet UIImageView *img29;
#property (weak, nonatomic) IBOutlet UIImageView *img30;
#property (weak, nonatomic) IBOutlet UIImageView *img31;
#property (weak, nonatomic) IBOutlet UIImageView *img32;
#property (weak, nonatomic) IBOutlet UIImageView *img33;
#property (weak, nonatomic) IBOutlet UIImageView *img34;
#property (weak, nonatomic) IBOutlet UIImageView *img35;
#property (weak, nonatomic) IBOutlet UIImageView *img36;
#property (weak, nonatomic) IBOutlet UIImageView *img37;
#property (weak, nonatomic) IBOutlet UIImageView *img38;
#property (weak, nonatomic) IBOutlet UIImageView *img39;
#property (weak, nonatomic) IBOutlet UIImageView *img40;
#property (strong, nonatomic) NSArray *imageViews;
#property CGPoint *holder1;
#property CGPoint *holder2;
#property CGPoint *holder3;
#property CGPoint *holder4;
#property CGPoint *holder5;
#property CGPoint *holder6;
#property CGPoint *holder7;
#property CGPoint *holder8;
#property (strong, nonatomic) NSMutableArray *holders;
#end
.m file
#import "DSAAssignmentViewController2.h"
#interface DSAAssignmentViewController2 ()
#end
#implementation DSAAssignmentViewController2
#synthesize lblDisplayPreviousInput;
#synthesize imgOriginal;
#synthesize img1;
#synthesize img2;
#synthesize img3;
#synthesize img4;
#synthesize img5;
#synthesize img6;
#synthesize img7;
#synthesize img8;
#synthesize img9;
#synthesize img10;
#synthesize img11;
#synthesize img12;
#synthesize img13;
#synthesize img14;
#synthesize img15;
#synthesize img16;
#synthesize img17;
#synthesize img18;
#synthesize img19;
#synthesize img20;
#synthesize img21;
#synthesize img22;
#synthesize img23;
#synthesize img24;
#synthesize img25;
#synthesize img26;
#synthesize img27;
#synthesize img28;
#synthesize img29;
#synthesize img30;
#synthesize img31;
#synthesize img32;
#synthesize img33;
#synthesize img34;
#synthesize img35;
#synthesize img36;
#synthesize img37;
#synthesize img38;
#synthesize img39;
#synthesize img40;
#synthesize passedData;
#synthesize imageViews;
#synthesize holder1;
#synthesize holder2;
#synthesize holder3;
#synthesize holder4;
#synthesize holder5;
#synthesize holder6;
#synthesize holder7;
#synthesize holder8;
#synthesize holders;
- (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.
// make jigsaw piece holders
//create 8 points where the jigsaw pieces (images) will be placed
CGPoint holder1 = CGPointMake(60, 644);
CGPoint holder2 = CGPointMake(140, 644);
CGPoint holder3 = CGPointMake(220, 644);
CGPoint holder4 = CGPointMake(300, 644);
CGPoint holder5 = CGPointMake(380, 644);
CGPoint holder6 = CGPointMake(460, 644);
CGPoint holder7 = CGPointMake(540, 644);
CGPoint holder8 = CGPointMake(620, 644);
// set up array of cgpoints
holders = [NSMutableArray arrayWithObjects:[NSValue valueWithCGPoint: holder1],[NSValue valueWithCGPoint: holder2], [NSValue valueWithCGPoint: holder3], [NSValue valueWithCGPoint: holder4], [NSValue valueWithCGPoint: holder5], [NSValue valueWithCGPoint: holder6], [NSValue valueWithCGPoint: holder7], [NSValue valueWithCGPoint: holder8], nil];
// set up array of images
imageViews = [NSArray arrayWithObjects:img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16, img17, img18, img19, img20, img21, img22, img23, img24, img25, img26, img27, img28, img29, img30, img31, img32, img33, img34, img35, img36, img37, img38, img39, img40, nil];
NSString *welcomeMessage = [NSString stringWithFormat:#"Welcome %#", passedData];
UIAlertView *alert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: welcomeMessage
message:#"Once you press \"Play\" the timer will start. Good luck!"
delegate:self
cancelButtonTitle:#"I want out!"
otherButtonTitles:#"Play",nil];
[alert show];
NSLog(#"x-coord: %f, y-coord: %f", holder1.x, holder1.y);
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
if ([imageViews indexOfObject:touchedView] != NSNotFound) {
// not not found means found!
[self animateFirstTouch:touchedView withLocation:location];
} else {
return;
}
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
//location of current touch
CGPoint location = [touch locationInView:self.view];
UIView *touchedView = [touch view];
[self animateReleaseTouch:touchedView withLocation:location];
}
- (void)viewDidUnload
{
[self setLblDisplayPreviousInput:nil];
[self setImgOriginal:nil];
[self setImg1:nil];
[self setImg2:nil];
[self setImg3:nil];
[self setImg4:nil];
[self setImg5:nil];
[self setImg6:nil];
[self setImg7:nil];
[self setImg8:nil];
[self setImg9:nil];
[self setImg10:nil];
[self setImg11:nil];
[self setImg12:nil];
[self setImg13:nil];
[self setImg14:nil];
[self setImg15:nil];
[self setImg16:nil];
[self setImg17:nil];
[self setImg18:nil];
[self setImg19:nil];
[self setImg20:nil];
[self setImg21:nil];
[self setImg22:nil];
[self setImg23:nil];
[self setImg24:nil];
[self setImg25:nil];
[self setImg26:nil];
[self setImg27:nil];
[self setImg28:nil];
[self setImg29:nil];
[self setImg30:nil];
[self setImg31:nil];
[self setImg32:nil];
[self setImg33:nil];
[self setImg34:nil];
[self setImg35:nil];
[self setImg36:nil];
[self setImg37:nil];
[self setImg38:nil];
[self setImg39:nil];
[self setImg40:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void) animateFirstTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.25, 1.25);
[UIView commitAnimations];
}
-(void) animateReleaseTouch:(UIImageView *)image withLocation:(CGPoint)location {
image.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
image.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
I can't tell if its all a bit of a mess or not. As you can see i've started with only 8 "holders", these are the CGPoints that represent the center of where the jigsaw pieces should be placed.
borrrden is correct. You've created a whole bunch of CGPoint pointer variables by declaring them as properties and synthesizing them. But then in your -viewDidLoad method you're declaring CGPoint structs--not CGPoint pointers--all with the same name as the properties you synthesized.
You don't need the holderN properties at all, to judge from the code. In fact, you don't even need the holderN variables in the -viewDidLoad method. You could easily get away with something like this:
- ( void )viewDidLoad
{
holders = [ NSMutableArray arrayWithObjects:
[ NSValue valueWithCGPoint: CGPointMake(60, 644) ],
...,
[ NSValue valueWithCGPoint: CGPointMake(N, N) ],
nil ];
...
}
Hard-coding the point coordinates is poor design, though. Your best option is to put the coordinates in a plist, which you can load on demand and stuff into an array. This'll mean tweaking the coordinates is just a matter of editing the plist. No recompiling required.
You are getting the message in your comment because you declare variables with the same name as your properties in the beginning of viewDidLoad.
NSPoint is not an object so you have to either use C array: NSPoint points[SIZE] or use NSValue container: [NSValue valueWithCGPoint: point]

Converting UITextField to UILabel through view Controllers

I'm sure there is a simple explanation for this.
I am looking to transfer the data (not store) but transfer the text the user types into a text field and display it as a UILabel in another ViewController.
I already know how to convert text entered by the user into a label on the same viewcontroller.
I guess my problem is importing.
the .h:
#interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
NSString *firstName;
NSString *secondName;
}
#property (nonatomic, retain) IBOutlet UITextField *firstPerson;
#property (nonatomic, retain) IBOutlet UITextField *secondPerson;
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
#property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
#end
the .m:
-(IBAction)calculate {
//Linked to UIButton
//This is the first View Controller.
// firstName = firstPerson.text;
// secondName = secondPerson.text;
secondViewController = [[ShowStats alloc] init];
}
my secondview controller .m (ShowStats):
#import "ShowStats.h"
#import "ViewController.h"
- (void)viewDidLoad
{
firstName = firstPerson.text;
secondName = secondPerson.text;
[super viewDidLoad];
}
Many thanks!
EDIT
ViewController.h
#import <UIKit/UIKit.h>
#import "ShowStats.h"
#interface ViewController : UIViewController {
IBOutlet UITextField *firstPerson;
IBOutlet UITextField *secondPerson;
IBOutlet UIButton *calculateButton;
//NSString *firstName;
// NSString *secondName;
}
#property (nonatomic, retain) IBOutlet UITextField *firstPerson;
#property (nonatomic, retain) IBOutlet UITextField *secondPerson;
//#property (nonatomic, retain) NSString *firstName;
//#property (nonatomic, retain) NSString *secondName;
#property (nonatomic, retain) IBOutlet UIButton *calculateButton;
-(IBAction)calculate;
#end
ViewController.m
#import "ViewController.h"
#import "ShowStats.h"
#implementation ViewController
#synthesize firstPerson, secondPerson;
//#synthesize firstName, secondName;
#synthesize calculateButton;
ShowStats *secondViewController;
-(IBAction)calculate {
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
}
ShowStats.h
#interface ShowStats : UIViewController{
IBOutlet UILabel *nameStats;
}
#property (nonatomic, retain) IBOutlet UILabel *nameStats;
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
#end
ShowStats.m
- (void)viewDidLoad
{
nameStats.text = [NSString stringWithFormat:#"%#", firstName];
//secondLabel.text = self.secondName;
[super viewDidLoad];
}
Make these properties in ShowStats class
#property (nonatomic, retain) NSString *firstName;
#property (nonatomic, retain) NSString *secondName;
and change this to this
-(IBAction)calculate {
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
secondViewController.secondName = secondPerson.text;
}
then set these strings to UILablel in your viewDidLoad
In ShowStats.h, add the following:
#property(nonatomic, copy) NSString* firstName;
#property(nonatomic, copy) NSString* secondName;
In ShowStats.m add/update the following:
#synthesize firstName, secondName;
//...
- (id) init {
if (self = [super init]) {
self.firstName = nil;
self.secondName = nil;
//...
}
return self;
}
- (void) dealloc {
self.firstName = nil;
self.secondName = nil;
//...
[super dealloc];
}
- (void)viewDidLoad {
//or even better, do this in viewWillAppear instead
firstLabel.text = self.firstName;
secondLabel.text = self.secondName;
//...
[super viewDidLoad];
}
Finally, in ViewController.m, implement calculate like this:
-(IBAction)calculate {
//Linked to UIButton
//This is the first View Controller.
// firstName = firstPerson.text;
// secondName = secondPerson.text;
secondViewController = [[ShowStats alloc] init];
secondViewController.firstName = firstPerson.text;
secondViewController.secondName = secondPerson.text;
//display the view controller here
[secondViewController autorelease];
}
If it is a navigation then in your SecondViewController you can call:
ViewController *viewController = [self.navigationController.viewControllers objectAtIndex:0];
firstName = [[viewController firstPerson] text];
secondName = [[viewController secondPerson] text];
Or you could do the following for a Single View app:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
ViewController *viewController = [appDelegate viewController];
firstName = [[viewController firstPerson] text];
secondName = [[viewController secondPerson] text];
* EDIT *
Add two labels to your .h file (nonatomic, retain) & synthesize in .m . Initialize the labels in viewDidLoad then set them (assuming they are called label1 and label2):
[label1 setText:firstName];
[label2 setText:secondName];

Change size of View in UYLModalViewController

I create an modal View controller. And In I crate TableView And TextField
In vertical position all ok!
Verticlal
But in horizontal a can see all of this
How can I resize my view for it?
Here the code of call ModalView
-(IBAction)buttonTapped:(id)sender{
UYLModalViewController *modalVC = [[UYLModalViewController alloc] initWithNibName:#"UYLModalViewController" bundle:nil];
modalVC.delegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:modalVC];
if (modalViewShowType==1)
{
nc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:nc animated:YES];
}
else{
nc.modalPresentationStyle = UIModalPresentationFormSheet;
nc.view.bounds = CGRectMake(0, 0, 320, 480);
[self presentModalViewController:nc animated:YES];
//nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//nc.view.frame = CGRectMake(0, 0, 320, 480);//it's important to do this after presentModalViewController
//nc.view.center = self.view.center;
}
[modalVC release];
[nc release];
}
and here the declaration of controller for modalView
#protocol UYLModalViewControllerDelegate
-(void) buttonDonePassed :(NSArray *) variables;
#end
#interface UYLModalViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
{
id<UYLModalViewControllerDelegate> delegate;
//id<UITextFieldDelegate> textdelegate;
// id<UITextField> txt;
IBOutlet UITableView *tblView;
IBOutlet UITextField *textField;
NSMutableArray *cellsArray;
BOOL isAddedNewRow;
//UITextField *textField;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier :(NSInteger *)cellRow;
//-(void) clickToTextField:(id)sender;
#property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate;
#property (nonatomic, retain) IBOutlet UITableView *tblView;
#property (retain, nonatomic) IBOutlet UITextField *textField;
#end
As I can see in debug mode when the device in horizontal position it doesn't go to the tableview delegate methods =(
1) Where is defined the methode :
-(IBAction)buttonTapped:(id)sender;
I think that there is a problem with presenting modal a viewController over an
UISplitViewController...try to present it over an other ViewController to test
2) the UISplitViewController can create some problems if you use it not correctly
example: try to addSubView its view ( you can't push it )
3) Verify with the auoresizeMask of UYLModalViewController view