Changing label's data using textField inout - uilabel

I want to change the label's text (which is embedded in a tableViewCell) using a textField data (which is embedded outside the tableViewCell).
Can anyone share the code please using objective-C.
Here is my TableViewCell.h file.
#import <UIKit/UIKit.h>
#interface TableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
Here is my storyboard controller file
#import <UIKit/UIKit.h>
#interface ViewController:UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *contacts;
}
- (IBAction)leftBtn:(id)sender;
- (IBAction)rightBtn:(id)sender;
- (IBAction)nextBtn:(id)sender;
- (IBAction)SendBtn:(id)sender;
#property (strong, nonatomic) IBOutlet UITableView *tabV1;
#property (strong, nonatomic) IBOutlet UITextField *txtField;
#end
Here I have the button action connection where I should I write the actual code to change the label's data using a text field.
- (IBAction)leftBtn:(id)sender {
}

Related

cocoa-Why there is an IBOutlet and a property that are of the same name?

I'm new to objective-c. When I'm reading some source code written by others, I encountered a problem.
I found that there is
IBOutlet NSPopover *popover;
as well as
#property NSPopover *popover;
PopoverViewController.h
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "TimerPopoverViewController.h"
#class TimerLogic;
#class TimerInfo;
#interface TimerPopoverDelegate : NSObject <NSPopoverDelegate> {
#private
IBOutlet NSPopover *popover;
IBOutlet NSWindow *detachWindow;
IBOutlet TimerPopoverViewController *viewController;
}
#property NSPopover *popover;
- (void)showPopover:(id)sender timerInfo:(TimerInfo *)timerInfo;
#end
I think they are different variables. However, I can't figure out what do they do?
As far as I'm concerned, the IBOutlet is to show a popover.
But what does the #property does?
This is either very old code or written in a very old (and now discouraged) style. The IBOutlet here is declaring an instance variable (ivar). The #property is declaring a property that is backed by the instance variable. In modern ObjC you should implement it this way:
PopoverViewController.h
#import <Cocoa/Cocoa.h>
#class TimerInfo;
// Things declared here are public
#interface TimerPopoverDelegate : NSObject <NSPopoverDelegate>
// You could leave this here if it is required by other parts of the program,
// but other parts of the program really shouldn't require it. See below.
// #property (nonatomic, readonly, weak) NSPopover *popover;
- (void)showPopover:(id)sender timerInfo:(TimerInfo *)timerInfo;
#end
PopoverViewController.m
// Generally avoid importing local headers into the .h unless you have to.
#import "TimerPopoverViewController.h"
// Things declared here are private. This is much better than the old #private.
#interface TimerPopoverDelegate ()
#property (nonatomic, readwrite, weak) IBOutlet NSPopover *popover;
#property (nonatomic, readwrite, weak) IBOutlet NSWindow *detachWindow;
#property (nonatomic, readwrite, weak) IBOutlet TimerPopoverViewController *viewController;
#end
(Currently popover is public, but you should avoid exposing an IBOutlet that way. Outside objects should not directly touch a view controller's outlets.)

How to add a UIView to an UIAlertView?

I have to create a custom AlertView with a view that contain some label. I create the .h and .m of CustomAlert
this is the CustomAlert.h.
#import <Foundation/Foundation.h>
#interface CustomAlert: UIView
#property (nonatomic, weak) IBOutlet UILabel *ok;
#property (nonatomic, weak) IBOutlet UILabel *ok1;
#property (nonatomic, weak) IBOutlet UILabel *ok2;
#property (nonatomic, weak) IBOutlet UILabel *ok3;
#property (nonatomic, weak) IBOutlet UILabel *ok4;
#property (nonatomic, weak) IBOutlet UILabel *ok5;
#end
and this is the CustomAlert.m.
#import "CustomAlert.h"
#implementation CustomAlert
#synthesize ok = _ok;
#synthesize ok1 = _ok1;
#synthesize ok2 = _ok2;
#synthesize ok3 = _ok3;
#synthesize ok4 = _ok4;
#synthesize ok5 = _ok5;;
#end
I also create the xib with just a view and i connect the label with all the "ok".
Now, i want to add this View to an AlertView with just an Ok button. How can i do it? I want to use it with ios 7 and 6.
Thanks!!
In iOS 7 you should not munge a UIAlertView like this - and there is no need, because thanks to custom view transitions you can make your own small presented view in front of your interface, so that it looks and acts like a UIAlertView but can contain anything you like.
I've written an online tutorial on how to do this:
http://programming.oreilly.com/2014/01/transcending-uialertview-on-ios-7.html
And there's a downloadable github project that goes with it:
https://github.com/mattneub/custom-alert-view-iOS7

How can I improve my attempt to create protected properties

#import "BGReviewController.h"
#interface BGReviewController (protected)
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
#property (weak, nonatomic) IBOutlet UIButton *dislikeButton;
#property (weak, nonatomic) IBOutlet UIButton *likeButton;
#property (weak, nonatomic) IBOutlet UIButton *post;
#property (weak, nonatomic) IBOutlet UIButton *cancel;
#property (weak, nonatomic) IBOutlet UITextView *textView;
#end
Then I add:
#synthesize backgroundImage = _backgroundImage;
#synthesize dislikeButton = _dislikeButton;
#synthesize likeButton = _likeButton;
#synthesize post = _post;
#synthesize cancel = _cancel;
#synthesize textView = _textView;
And I got error:
/business/Dropbox/badgers/BadgerNew/BGReviewController.m:32:13: Property declared in category 'protected' cannot be implemented in class implementation
Should I declare the synthesize in the implementation file of the category and then put the ivars explicitly?
you cant #synthesize in a category, you have to do the getters and setter manually
check out this answer
Replace
#interface BGReviewController (protected)
With
#interface BGReviewController ()

UITextField bind

I can't figure out why that code is not working for me.
ViewController.h
...
#property (nonatomic, copy) UITextField *textField;
...
ViewController.m
-(void)viewDidLoad
{
[self.textField addTarget:self
action:#selector(textIsChanged:)
forControlEvents:UIControlEventEditingChanged];
}
-(void)textIsChanged:(id)sender;
{
NSLog(#"Changed");
}
When I type something in the textField textIsChanged method is never invoked.
You should declare textField as an IBOutlet like this:
#property (nonatomic, retain) IBOutlet UITextField *textField;
or, if you are using ARC (Automatic Reference Counting):
#property (nonatomic, strong) IBOutlet UITextField *textField;
and bind it from the xib file in interface builder.

Textfield return (null) no matter what

I have searched stackoverflow for similar problems and have found some, but they did not resolve my problem. I have 3 textfields (name,address,phone) from which I want to get the text. I have declared them in the (.h) file, also the #property, and then #synthesized them in the (.m) file. I have a IBAction for a button declared in the (.h) file and linked up correctly. Now when I push this button I want to get the values from the textfields but NSLog shows they are all (null) even before I do anything with the textfields. Its very simple code, i can't understand why it returns null.
//CoreDataViewController.h
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
#property (strong, retain) IBOutlet UITextField *name;
#property (strong, retain) IBOutlet UITextField *address;
#property (strong, retain) IBOutlet UITextField *phone;
#property (strong, retain) IBOutlet UILabel *status;
- (IBAction) saveData;
#end
//CoreDataViewController.m
#import "coreDataViewController.h"
#import "AppDelegate.h"
#implementation coreDataViewController
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;
- (void) saveData
{
NSLog(#"Name %# Address %# Phone %#",self.name.text,self.address.text,self.phone.text);
...some more code (commented out)....
}
IMO you have incorrectly synthesized iVars.
You use syntax:
synthesize name=_name;
but in the .h file you have:
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
Change this part to:
#interface coreDataViewController : UIViewController {
UITextField *_name;
UITextField *_address;
UITextField *_phone;
UILabel *_status;
}
Just change below code
write synthesize like this
#synthesize name;
#synthesize phone;
#synthesize address;
#synthesize status;
ratherthen
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;