A Button to make a TextView from invisible to visible - xcode

iam a newbie in Xcode programming and i didnt find the right answer in another Tread.
My Question: I have a Detailview with a CardQuestion(TextView) and a CardAnser(TextView).
How is the method to change the invisible Answer to visible.
On Action the Button "Show Answer".
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = self.chosenCard.name;
self.cardName.text = self.chosenCard.name;
self.cardQuestion.text = self.chosenCard.question;
self.cardAnswer.text = self.chosenCard.answer;
}
- (void)viewDidUnload
{
[self setCardName:nil];
[self setCardQuestion:nil];
[self setCardAnswer:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)toAnswerButton:(id)sender{
}
#end
I hope you can understand my question.

UIView subviews (including UILabel, UITextField and UITextView) have a hidden property. Set that to YES to hide a view and to NO to unhide it. You can also set this property in Interface Builder.

Related

traffic buttons not responding in MacOS application

I am creating an application on MacOS and I am having this problem. I am using custom traffic buttons. When the window is not active if I click they do not respond, what I get is the window becoming active.
How could I fix that so the buttons will respond even if the window is not the active one.
I have them added to a custom view, here is what I have:
My View:
#implementation TrafficView
- (id)init {
if ((self = [super init])) {
trackingArea_.reset([[NSTrackingArea alloc]
initWithRect:[self bounds]
options:(NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways |
NSTrackingInVisibleRect)
owner:self
userInfo:nil]);
[self addTrackingArea:trackingArea_.get()];
}
return self;
}
- (void)dealloc {
[super dealloc];
}
- (BOOL)acceptsFirstResponder {
return YES;
}
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
return YES;
}
- (void)mouseEntered:(NSEvent*)event {
mouseInside_ = YES;
for (NSView* view in self.subviews)
[view setNeedsDisplay:YES];
}
- (void)mouseExited:(NSEvent*)event {
mouseInside_ = NO;
for (NSView* view in self.subviews)
[view setNeedsDisplay:YES];
}
- (BOOL)_mouseInGroup:(NSButton *)button {
return mouseInside_;
}
#end
Now to add the buttons I do this in the window implementation (I will post the code for only one button)
trafficView_.reset([[TrafficView alloc] init]);
[self.frameView addSubview:trafficView_];
// close button is declared as NSButton
closeButton_ =
[NSWindow standardWindowButton:NSWindowCloseButton
forStyleMask:NSTitledWindowMask];
[trafficView_ addSubview:closeButton_];
Note that my custom view (trafficView_) is added to the NSThemeFrame class, self.frameView
- (NSView*)frameView {
return [[self contentView] superview];
}
I do not why the buttons do not respond.
Could someone help on this?
Thanks in advance

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..

Allow to view image in landscape in portrait-only app

I am making an iPhone and iPod app that I will make in portrait mode only. There comes a point in the app where if the user touches a picture, it will make itself fullscreen. The way I do that is via a segue to another view controller, where a UIImageView takes the whole space. I would like to be able to rotate the device in landscape to view the picture in landscape.
How it that possible?
In a second phase: I would like to know how to make the view fullscreen, so the picture could fill the entire screen.
Basically: I want the picture to behave just like the twitter app. :)
Thanks
EDIT: here is the code in my Class to view the image
#import "ImageViewer.h"
#interface ImageViewer ()
#end
#implementation ImageViewer
#synthesize scrollView;
#synthesize imageView;
#synthesize image;
- (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.
CGRect imageFrame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
self.imageView.frame = imageFrame;
self.scrollView.contentSize = imageFrame.size;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)sender
{
return self.imageView;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
NSLog(#"rotate.");
return YES;
}
- (void)viewDidUnload {
[self setImageView:nil];
[self setScrollView:nil];
[super viewDidUnload];
}
#end

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?

Is this a bug for EKEventEditViewController

I found EKEventEditViewController is not correct in
UIInterfaceOrientationPortraitUpside.
Try this demo from your site, I just changed code as below, put simulator to
UpSide Down Portrait mode, then click "+" button, you will find the screen in
flash, this is due to dialog is upside in short time.
Then you can try it on device turn to UpSideDown mode, you will see what I am talking:)
I want to know why they have different view in Simulator or iPad even if it is
not a bug.
Bug in SimpleEKDemo
Basically you would want to Create your own class that inherits from EKEventEditViewController and use that everywhere you would use normally use EKEventEditViewController. For example, KonopEventEditViewController.
KonopEventEditViewController.h is as follows
#import <EventKitUI/EventKitUI.h>
#interface KonopEventEditViewController : EKEventEditViewController
#end
KonopEventEditViewController.m is as follows
#import "KonopEventEditViewController.h"
#interface KonopEventEditViewController ()
#end
#implementation KonopEventEditViewController
- (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.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end

Resources