NSScrollView in Cocoa - objective-c

I am trying to get an NSSrollView with an NSTextField in it to work, however the scrollbars do not seem to respond to anything that I am coding.
I am declaring the NSScrollView as an IBOutlet, add it as a property and then synthesizing it. However, it's to no avail.
The scrollbars do appear when I resize, however they serve no function at the moment.
I have tried to use the apple documentation, but again, no joy there.
Any help? Thanks!

As You was saying "For my purposes, any container which scrolls will do the trick" You can use NSTextView in an NSScrollView. And for setting text You need to use setString instead setStringValue.
Example how to set text in NSTextView:
.h
IBOutlet NSTextView *textView;
.m
-(void)awakeFromNib {
NSString *string = #"my text";
[textView setString:string];
}
Don't forget IBOutlet NSTextView not NSScrollView.
NSTextView is in NSScrollView:

Related

Disable editing in text view

I'm using Xcode coding an ios7 app, whenever I try to make a text view it is editable by the user. How can I fix this so it can not be editable? It is editable in the iPhone simulator, what property do I need to change to disable this and where can I find it?
If you click on the textView in the storyboard (if you created it in the storyboard), then you can open the attributes inspector on the right and there is a checkbox that says editable. If it was not created in the storyboard, then there is a property
textView.editable = NO;
Try:
//.h
#interface YourViewController:UIViewController<UITextViewDelegate>
#property (strong, nonatomic) IBOutlet UItextView *textView;
#end
//.m
-(void) viewDidload
{
_textView.delegate =self;
}
- (BOOL)textViewDidBeginEditing:(UITextField *)textField
{
return NO;
}
If you are using storyboard, click on UITextField in storyboard and there is a property called behaviour editable: remove the tick than and build.

Making a default property unaccessible?

A UITableViewCell by default has a textLabel property. Now, I've subclassed UITableViewCell, and have set up my own text layout system that doesn't use textLabel. To reduce chance of error, I'd like to make the default property textLabel unavailable to the compiler (auto-complete), and that if I try to access it outside the class, the code will not compile.
Making the property readonly will still allow me to access and change the label's properties, so that won't work.
Is there any way to do this?
Edit:
So the closest I've gotten so far is redeclaring the property in my subclass and deprecating it:
#property (nonatomic) UILabel *textLabel NS_DEPRECATED_IOS(2_0, 3_0);
which currently gives me a warning if I try to access the property. But this doesn't completely hide it from the compiler, and it also gives me a warning "Availability does not match previous declaration".
Ok, figured it out. You can use the UNAVAILABLE_ATTRIBUTE macro to accomplish this:
#property (nonatomic) UILabel *textLabel UNAVAILABLE_ATTRIBUTE;
and then doing cell.textLabel gives a compile error: textLabel is unavailable.
Its readonly. You can access but not assign. See header file.
#property(nonatomic,readonly,retain) UILabel *textLabel
//Example
#interface myCell : UITableViewCell
{
}
#end
#implementation myCell
-(void)check
{
//You can access
UILabel *label = self.textLabel;
//You canot assign
self.textLabel = label;
}
#end

NSImageView added with Interface Builder is null

I've the following problem:
I've added a NSImageView to my NSWindow. I set the controller of my Window as the file's owner. I can open my window, click on buttons. It works great. But when I try to set an icon to the ImageView, nothing happens because it's null.
What could be the reason it's null? I checked, and it's connected to the IBOutlet.
Thx
Remember, Just connecting to the IBOutlet will not allocate the memory for given variable. Since you haven't allocated the memory it shows null.
So, do this first.
#property (nonatomic) IBOutlet NSImageView *imageView;
and then
#synthesize imageView = _imageView;
and then before you set the image you need to alloc and init the _imageView.
like,
_imageView = [NSImageView alloc] init];

What's the correct way to set the text of a UILabel that's part of an IBOutletCollection

I have a series of UILabels that form part of an IBOutletCollection
#property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labelCollection;
I have sequentially set the tags of the UILabels to 0,1,2,3 ... and I have sorted the *labelCollection by tag number. Thus, object '0' in the IBOutletCollection array is the UILabel with tag '0' etc.
Using the following function I can update the text of the UILabel at a particular obj/tag:
- (void) updateLabelAtTag:(int)objId {
[[self.labelCollection objectAtIndex:objId] setText:#"my new text"];
}
}
This works fine, however, when you click on the setText: in the IDE, Xcode Quick Help complains
setText:
#property(nonatomic, copy) NSString *text
iOS (2.0 and later)
Deprecated: Use the textLabel and detailTextLabel properties instead.
The text of the cell.
UITableViewCell.h
For the life of me I can't figure out what UITableViewCell has to do with this situation. I certainly don't appear to be able to access the textLabel or detailTextLabel properties.
Question: Am I using a deprecated property, or has Xcode got it wrong in this instance?
Xcode. I suspect
[(UILabel *)[self.labelCollection objectAtIndex:objId] setText:#"my new text"];
would make it go away.

Setting the UI Labels of NSTextfield dynamically in cocoa

I need to set the labels of the UI dyanmically..
I want be read the text from an xml file and would like to set the text to the controls in the NIB.
I guess i can recognise the conrol by using the TAG attribute of the control.
Now i would like to get all the objects in the window(controls in the Nib) into an array?
Please suggest me on this.
In your code you'll want to create a link to your control. In xcode, in your .h file put something like:
#interface Mycontroller : UIViewController {
IBOutlet UILabel *namelabel;
}
#property (nonatomic, retain) IBOutlet UILabel *namelabel;
-(void)ChangeName:(NSString *)toName;
#end
Then in your .m file put something like:
#implementation ProjectCell
#synthesize namelabel;
-(void)ChangeName:(NSString *)toName {
[namelabel setText:#"your new string"];
}
You then want to open your nib in interface builder. Select your label and go to the inspector (Tool Menu > Inspector). Go to the Connections tab (blue circle w/ white arrow, and then click and drag the circle by New References Outlet from there to File's Owner in the nib window. Select "namelabel" from the popup. They're now linked and changing namelabel in code will change that specific label that you setup in interface builder.
I agree with the above soultion....
I had to set the title of each textfield and buttons in applicationdidFinishLaunching function.