I have created one segmented control and a text view in my .xib file and I have declare it in .h file as
#interface controlsViewController : UIViewController {
IBOutlet UISegmentedControl *colorChooser;
IBOutlet UITextView *setText;
}
#property (nonatomic,retain) UISegmentedControl *colorChooser;
#property (nonatomic,retain) UITextView *setText
but it shows me warning on both lines of #property
Can anyone tell me why it warns me?
My guess would be that you don't have a #synthesize or #dynamic in your implementation. That would generate compiler warnings.
The position of the IBOutlet wound not generate a compiler warning as it's a marco of nothing. It's used by xcode resource editor (or the older Interface Builder) to indicate it's a outlet property and doesn't generate any code.
#interface controlsViewController : UIViewController {
UISegmentedControl *colorChooser;
UITextView *setText;
}
#property (nonatomic,retain) IBOutlet UISegmentedControl *colorChooser;
#property (nonatomic,retain) IBOutlet UITextView *setText;
You need to synthesize the property in your .m file. You won't get the error then.
Related
So in the storyboard i have a UIViewController class called FormViewController. I set the ViewController in the storyboard to use that:
I then have the three text fields in the header file:
#import <UIKit/UIKit.h>
#interface FormViewController : UIViewController
#property (strong, retain) IBOutlet UITextView *firstName;
#property (strong, retain) IBOutlet UITextView *lastName;
#property (strong, retain) IBOutlet UITextView *email;
- (IBAction) save:(id)sender;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
#end
However, when i try to connect the ones in the storyboard to the view controller, it doesnt pop up.
Any ideas?
UITextField and UITextView are two very different classes—you have created UITextField instances but your outlets are typed as UITextView.
Just change your outlet types to UITextField and all should be well!
(UITextView, for the record, is a scrolling, often editable field, more like a word processor.)
I added a UITextView to storyboard that I created a property for and connected in a subview of UIView (called FieldView) in this case. The property was like this
#property (strong, nonatomic) UITextView * instructions;
That FieldView is a property of the viewController
#property (strong, nonatomic) IBOutlet FieldView *fieldView;
When I wanted to hide the UITextView *instructions with code in the viewController, I declared the property in the .h file so that I could eventually do this when a button was pressed
self.fieldView.instructions.hidden = YES;
However, xCode's giving me an error
illegal redeclaration of property in class extension FieldView, attribute must be readwrite while its primary must be readonly
When I added readwrite in both the .h and .m files
#property (weak, nonatomic, readwrite) IBOutlet UITextView *instructions;
it said `perhaps you intended this to be a readwrite redeclaration of a readonly public property
What is the correct way to do what I am trying to do?
To resolve your issue you need declare readonly property in .h file and readwrite property in .m file:
//FieldView.h
#interface FieldView
#property (nonatomic, readonly, strong) UITextView *instructions;
#end
// FieldView.m
#interface FieldView()
#property (nonatomic, readwrite, strong) IBOutlet UITextView *instructions;
#end
I Also got same issue,
If same name property is declared in .h file and you are again declaring it in extension then you will get this error.
So renaming property name will resolve the issue.
For me, I had to remove one of the properties in AppDelegate.h
Before:
#property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
#property (nonatomic, strong) UIWindow *window;
After:
#property (nonatomic, strong) UIWindow *window;
I have checked thoroughly for a solution to this (notably here: Can't connect IBOutlet in Interface Builder) but cannot see the solution. I have a UITextView that I am using as a text area in a form. I have connected it to this class member in IB:
IBOutlet UITextView *notes;
here is my .h
#import <UIKit/UIKit.h>
#import <AddressBookUI/AddressBookUI.h>
#interface U2MIDetailController : UIViewController <UITextFieldDelegate, UITextViewDelegate> {
IBOutlet UIButton *confirmButton;
IBOutlet UITextView *notes;
}
#property (nonatomic, retain) IBOutlet UITextView* notes;
#property ABRecordRef personObject;
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#end
and my .m, the relevant bits:
#synthesize notes;
- (void)viewDidLoad
{
[super viewDidLoad];
//set up delegates for keyboard hiding
notes.delegate = self;
notes.text = #"Notes";
...
}
In the links I've found some have solved this issue by checking the File's Owner "Class" attribute on the Identity inspector. How do I do that? I have attached a pic of the hierarchy which looks correct to me, the identity inspector doesn't jump out at me either as having any suspicious properties.
Here is a shot of the storyboard:
and here is how it looks int he simulator:
check your scrollview frame either it is fit to frame or not. put blackground color you know where you did mistake
I am working with an iPhone application in Xcode and I want to use a segmented control with 4 different choices.
I am wondering what I am doing wrong and why the NSLog messages don't show when I click on it?
This is my code:
.h file:
#import <Foundation/Foundation.h>
#interface Format : UIViewController{
IBOutlet UISegmentedControl *papper;
}
#property (nonatomic, retain) IBOutlet UISegmentedControl *papper;
-(IBAction)papperskontrollSwitched:(id)sender;
.m file:
#import "Format.h"
#implementation Format
#synthesize papper;
-(IBAction)papperskontrollSwitched:(id)sender{
if(papper.selectedSegmentIndex==0){
NSLog(#"A5 valdes");
}
else if(papper.selectedSegmentIndex==1){
NSLog(#"A4 valdes");
}
else if(papper.selectedSegmentIndex==2){
NSLog(#"A3 valdes");
}
else if(papper.selectedSegmentIndex==3){
NSLog(#"Visitkort valdes");
}
}
#end
Try deleting the stuff in the brackets:
{
IBOutlet UISegmentedControl *papper;
}
There's no need for it when you have this:
#property (nonatomic, retain) IBOutlet UISegmentedControl *papper;
Having an ivar and a #property shouldn't matter here and indeed when I'm using this exact code in a test project it is working perfectly.
Ensure your UISegmentedControl is connected to the papper outlet in Interface Builder and you've connected the UISegmentedControl's 'Value Changed' action to -(IBAction)papperskontrollSwitched:
What is the technical difference between them and which is the method recommended by Apple?
// 1
#interface CocoaQuizViewController : UIViewController
{
IBOutlet UILabel *myLabel;
}
#end
// 2
#interface CocoaQuizViewController : UIViewController
{
IBOutlet UILabel *myLabel;
}
#property (nonatomic, retain) IBOutlet UILabel *myLabel;
#end
// 3
#interface CocoaQuizViewController : UIViewController
{
UILabel *myLabel;
}
#property (nonatomic, retain) IBOutlet UILabel *myLabel;
#end
// 4
#interface CocoaQuizViewController : UIViewController
#property (nonatomic, retain) IBOutlet UILabel *myLabel;
#end
The default is (generated automatically if you drag and drop outlet directly from xib to source class):
#interface CocoaQuizViewController : UIViewController
#property (nonatomic, weak) IBOutlet UILabel *myLabel;
#end
All are quite OK.
With new LLVM you are supposed to do 4th one.
#interface CocoaQuizViewController : UIViewController
#property (nonatomic, retain) IBOutlet UILabel *myLabel;
//even you use strong and weak intead of retain,assign,copy
#end
In earlier days, you were doing 1, 2 and 3. Now most of the thing is atomatcally done by the compiler. So your work is now easier than never before.
With New Compiler which comes with XCode4.4 and onwards gives you auto-synthesize for all the properties you declare. ivars also get created prefixed with your property name.
The 4th one, Because Now Apple has recommended all developers to make use of properties.
A couple of thoughts:
Your fourth example avoids a whole category of possible bugs that can plague the first three examples, where you can accidentally end up with two ivars (e.g. if you omitted the #synthesize, the compiler would generate an ivar called _myLabel, your myLabel ivar wouldn't be used, and, thus, would end up being redundant and only serve as a possible source of confusion).
If you use ARC (which I'd encourage, if you can), then clearly that retain reference becomes weak.
You probably shouldn't be "writing" the IBOutlet code yourself anyway. It's just an opportunity to introduce a bug. In IB, click on the "assistant editor" to show your code while working on IB, and then control-drag (or right-click-drag) from the control to the code, and IB will write your code for you! See https://stackoverflow.com/a/15551101/1271826 for screen snapshots.