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;
Related
What made the difference
#property (strong, nonatomic) and #property (nonatomic, strong) in ios.
i will define iboutlet for example uilabel like this
#property (strong, nonatomic) IBOutlet UILabel *label1;
and i see many time in this site
#property (nonatomic, strong) NSString* str;
What is the difference between the two property.
There are no differences in the logic. They represent the same thing but with different order.
Usually in IBOutlets you have #property (weak, nonatomic) because it is auto generated when you ctrl+drag from interface builder.
However, most people prefer the second form because the "nonatomic" is used in most of the cases in ios and therefore it is easily ignored.
There is no difference. But in apple sample codes and most frequently we use :
#property (nonatomic, strong)
From my MCSettingsFormViewController, I want to set MatchCenterViewController's didAddNewItem BOOL property, but without making use of a segue.
I've imported MatchCenterViewController.h, which contains that property like so:
#property (assign) BOOL didAddNewItem;
However, when I try to set it like this: MatchCenterViewController.didAddNewItem = YES;, it says "property didAddNewItem not found on object of type 'MatchCenterViewController'".
I assume this is because I haven't defined what MatchCenterViewController is. If so, how can I do this property so it sets the property correctly?
edit:
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#import "WebViewController.h"
#import "WSCoachMarksView.h"
#import "SLExpandableTableView.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (strong, nonatomic) NSString *itemSearch;
#property (strong, nonatomic) NSString *itemPriority;
//#property (strong, nonatomic) IBOutlet UITextField *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#property (strong, nonatomic) NSString *matchingCategoryCondition;
#property (strong, nonatomic) NSString *matchingCategoryLocation;
#property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryId;
#property (strong, nonatomic) NSArray *matchCenterArray;
#property (strong, nonatomic) NSString *searchTerm;
#property (strong, nonatomic) NSString *itemURL;
#property (assign) NSInteger expandedSection;
#property (assign) NSInteger rowCount;
#property (assign) BOOL didAddNewItem;
#property (assign) BOOL results;
#property (strong, nonatomic) IBOutlet UIButton *editButton;
#property (weak, nonatomic) IBOutlet UIButton *moreButton;
#property (strong) NSMutableSet *expandedSections;
#end
#interface MoreButton : UIButton
#property (assign) NSInteger expandedSection;
#property (assign) NSInteger sectionIndex;
#end
MCSettingsFormViewController.h:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <Parse/Parse.h>
#import "MatchCenterViewController.h"
#interface MCSettingsFormViewController : UIViewController
#property (strong, nonatomic) NSString *minPrice;
#property (strong, nonatomic) NSString *maxPrice;
#property (strong, nonatomic) NSString *itemCondition;
#property (strong, nonatomic) NSString *itemLocation;
#property (strong, nonatomic) NSString *searchTerm;
#property (strong, nonatomic) NSString *itemPriority;
#property (strong, nonatomic) IBOutlet UITextField *tf;
#property (strong, nonatomic) IBOutlet UITextField *tf1;
#property (strong, nonatomic) IBOutlet UITextField *tf2;
#end
You need to use an instance of MatchCenterViewController not the name of the class. Presumably, somewhere in your app there's a reference to a MatchCenterViewController object. You can either access that reference or pick a different way of letting it know about the change.
For example, if your two controllers aren't connected to each other, you could post a notification in MCSettingsFormViewController and react to it in MatchCenterViewController.
For more specific suggestions, I'd need to know how both controllers are created and presented.
When you instantiate MatchCenterViewController, you could set it as a delegate of MCSettingsFormViewController. That way, the MatchCenterViewController defines itself as the instantiated version of the class to be edited by the MatchCenterViewController.
Here is a basic tutorial for delegates: http://www.tutorialspoint.com/ios/ios_delegates.htm
So based off of your headers, it looks like either your MCSettingsFormViewController doesn't have a property of type MatchCenterViewController-- or that property is private.
In the former case, you need to add a property to your MCSettingsFormViewController with type MatchCenterViewController.
In the latter you aren't initializing your MatchCenterViewController property.
So first, make sure you have that public/private property.
Then, when you first create and show your SettingsFormViewController, set this property to your MatchCenterViewController instance. Now your SettingsForm has a reference to the proper instance you're looking for.
At this point, you can set the property on the MatchCenter
I want to add my custom NSObject class to other as property, is that possible?
Class look like this:
#interface PlaceHolder : NSObject
#property (strong, nonatomic) NSString *name;
#property (strong, nonatomic) NSString *description;
#property (strong, nonatomic) NSString *webPage;
I want to make it property of my other class to initialize it once, and then work with properties - name, description. webpage and other..
Do i need to create a category? Or there is another way to achieve this?
Any advice would be appreciated, thank you.
Just add a property to the class that needs to use it
#property (strong, nonatomic) PlaceHolder *placeHolder;
I'm following along with Apple's "Hello" tutorial on iOS, and I'd like to know why it's necessary to declare the "userName" variable (to be accessed in code later). Isn't it generated by the synthesize statement?
#interface HelloWorldViewController : UIViewController {
NSString *userName;
}
- (IBAction)changeGreeting:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UITextField *testField;
#property (nonatomic, copy) NSString *userName;
And here's the implementation of synthesize:
#synthesize label=_label;
#synthesize testField=_testField;
#synthesize userName=_userName;
It wasn't always generated by the property/synthesize. That's a relatively new addition to Objective-C. The tutorial was probably written before this was the case.
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.