I have the following code to change the text of the button from "Button" to "Press Me!":
[self.aButton setTitle:#"Press Me!" forState:UIControlStateNormal];
However, when I run the simulator, it shows the text of both and it overlaps. I tried constricting the button, but then after I ran the simulator again, there were two buttons, one with the default text of "Button", and the other with "Press Me!". I also tried deleting the default text of the button from the utilities panel, but that didn't work either.
How do I fix this?
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIButton *aButton;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.aButton setTitle:#"Press Me!" forState:UIControlStateNormal];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonPressed:(id)sender {
self.view.backgroundColor = [UIColor orangeColor];
}
#end
Related
I am learning how to create unwind segue. I created two VCs, „ViewoController“ and „MessageViewController“. The first one contains a button while the latter is embedded in a NavigationController and it has two barButtons „Cancel“ and Save“.
As far as I know, to create the unwind segue, the „Cancel“ and/or the „Save“ buttons in „MessageViewController“ must be linked to the EXIT icon in its ViewController which „MessageViewController“.
The problem I have is, when I can not link the barButton to the EXIT icon
please let me know how to link the barBurron to the EXIT icon in order to have the method "backToViewController" called
viewController.m
#import "ViewController.h"
#import "MessageViewController.h"
#interface ViewController ()
#property (strong, nonatomic) IBOutlet UIButton *buttonNext;
#end
#implementation ViewController
- (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.
}
-(void) backToViewController:(UIStoryboardSegue *)segue {
}
#end
messageViewController:
#import "MessageViewController.h"
#import "ViewController.h"
#interface MessageViewController ()
#property (strong, nonatomic) IBOutlet UIBarButtonItem
*barButtonSave;
#property (strong, nonatomic) IBOutlet UIBarButtonItem
*barButtonCancel;
#property (strong, nonatomic) IBOutlet UITextField
*textFieldMessage;
#end
#implementation MessageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
Your method signature is not quite right. In order for Xcode to recognize it for use as an Exit / Unwind Segue, it needs to return IBAction.
Changing it to:
- (IBAction) backToViewController:(UIStoryboardSegue *)segue;
should solve your problem.
I create a UITableView with option content to Static Cells in the Editor. I would like to translate some words with LocalizedString but the UILabel text didn't change. I do this :
the UIlabel boulet belong to a cell in the section of the UITabeView
.h
#property (weak, nonatomic) IBOutlet UILabel* labelToken
.m
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"%#", self.labelToken); // => OUTPUT (null)
self.labelToken.text = [NSString stringWithFormat:#"%# :", NSLocalizedString(#"TOKEN", nil)];
}
#import <UIKit/UIKit.h>
#interface ViewController : UITableViewController
#property (nonatomic, weak) IBOutlet UILabel *labelToken;
#end
////Implementation File
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.labelToken setText:[NSString stringWithFormat:#"%#",NSLocalizedString(#"HELLO", #"HELLO")]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
/////
You have to link labeltoken outlet to static cell's label in storyboard.
I found the solution. When i clicked on Localized on the StoryBaord, it has generate 3 sub files of Storyboard my (fr, zn, cn).My solution it's to delete the Storyboard and restoring from a versioning software.
Thanks for your help.
Can change text of UIlabel in static cells with below method well.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
simple codes..
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)dragout:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (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.
}
- (IBAction)dragout:(id)sender {
NSLog(#"-----");
}
#end
and in Storyboard, there is 1 button which size is fit in text "button". Link 'sent event:touch drag outside" to "dragout" IBAction.
When I touch button inside and drag my finger to outside of button, i need move more than button size to call "dragout" IBAction. Nearly 3x width&height size. Why is this happens? Thx for read.
Can anyone help me to understand what is going wrong with my function below pls?
I'm fairly new to native IOS dev.
I wanted to implement a side panel into our app using this tutorial (http://www.appcoda.com/ios-programming-sidebar-navigation-menu/).
All that works fine and is straightforward enough - but I wanted to trigger the reveal functionality via a standard button rather than a dynamic button in the header - to suit our design..
The original code is as follows -
#import "SWRevealViewController.h"
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = #selector(revealToggle:);
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
to replicate that functionality triggered by a button I added the following to the .h file -
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (weak, nonatomic) IBOutlet UIButton *revealLeftBtn;
- (IBAction)btnClickRevealL:(id)sender;
and the following in my .m file
- (IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
I get the error 'suspected identifier' for the above lines - I dont understand how the functions triggered with the previous method and not with the above - can anyone help?
Cheers
for reference this is the entire .M file -
#import "MainViewController.h"
#import "SWRevealViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"";
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
[self.navigationController.navigationBar setTranslucent:TRUE];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
#end
This line:
(IBAction)btnClickRevealL:(id)sender {
[self.revealViewController];
[#selector(revealToggle:)];
}
Does nothing.
I guess this is what you want to do:
[self.revealViewController revealToggle:sender];
When you set the target and the action of a button, you set which class is doing the action (target) and what method is called (action).
that's the equivalent of doing [target action]
- (IBAction)logInBtnClicked:(id)sender {
//Remove WhiteSpace from start of uitextfield
self.emailIdTxtFldRef.text = [self.emailIdTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
self.passwordTxtFldRef.text = [self.passwordTxtFldRef.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
if ([self.emailIdTxtFldRef.text isEqualToString:#""]||[self.passwordTxtFldRef.text isEqualToString:#""]) {
[self showMessage:#"All fields are mandatory" withTitle:#"Error"];
}else{
SWRevealViewController *revealVC = [self.storyboard instantiateViewControllerWithIdentifier:#"swRevealViewContoller"];
revealVC.delegate=self;
[[UIApplication sharedApplication]keyWindow].rootViewController = revealVC;
}
}
I'm new in iOS Development for iPhone. I can not dismiss keyboard, nothing works. Please help me, maybe I didn't notice anything?
My .h file:
#import "UIKit/UIKit.h"
#interface ViewController : UIViewController <UITextViewDelegate>
#property (weak, nonatomic) IBOutlet UITextField *textField;
#end
My .m file:
#import "ViewController.h"
#import "UIKit/UIKit.h"
#interface ViewController ()
#end
#implementation ViewController
- (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.
}
-(BOOL) textFieldShouldReturn: (UITextField *) textField{
[textField resignFirstResponder];
return YES;
}
#end
Hi this is a simple mistake. You have not set the delegate. You can do this by..
- (void)viewDidLoad
{
[super viewDidLoad];
textField.delegate = self;
}
Please add textField.delegate = self; to your viewDidLoad.
Most likely you forgot to set the delegate for textField. Inside your storyboard or nib file, drag your UITextField's delegate to your ViewController.