Why Can I edit UITextView content by textstograge property if is readonly? - uitextview

reading from Apple Documentation for UITextView , I read this for textStorage property
The text storage object holding the text displayed in this text view. (read-only)
Declaration
OBJECTIVE-C
#property(nonatomic, readonly, strong) NSTextStorage *textStorage
But in my professor's notes
[self.body.textStorage
setAttributes:#{NSForegroundColorAttributeName : sender.backgroundColor}
range:self.body.selectedRange];
How it's possible edit attributes of textStorage if is readonly?

The property is a pointer to an NSTextStorage object. The readonly attribute marks the property as read only, in this case it means the pointer cannot be changed.
It does however not say anything about whether the object it points to is mutable or not. So you can edit the current textStorage but not replace it with a different NSTextStorage object.

Related

How can i link to attribute of an instance of a class

In an EA model I have a class. The class defines an attribute. I want to be able to have an instance of this class (an object) with the attribute visible on a diagram and the ability to link specifically to that attribute (as in the Link to Element Feature option).
Is it possible?
Yes and no. You need to set the run state of the object
Once the following dialog is completed, it can look like
The value is free text and not linked to the original attribute, but better than nothing.

Add readonly attributes (getters) to NSManagedObject

I have a ruby class and a match definition in core data.
There is a NSData field 'image_data' to store my image.
In my ruby class, i was thinking to add a getter to return an UIImage.
However, i get an error saying "undefined method `image' for #"
What do i need to do to get around this?
class ActivityImage < NSManagedObject
def image
UIImage.imageWithData(image_data)
end
end
I think what you're looking for is a way of creating a "Transformable Attribute".
If you read through that guide, you'll get to understand what transformable attributes are, hopefully you're using Xcode's model editor so you can just create the attribute in there, but otherwise you'll just have to pull some hackery to get the entity then create the image attribute and set it as transformable.

UITextField: can't type text but smilies, copy/paste, and backspace is fine

I think this is strange, I have made my own class that inherits from UIAlertView. In this class I add a UITableView as subview and the cells contains a UILabel and a UITextField.
the class implements: UITableViewDelegate, UITableViewDataSource and UITextFieldDelegate,
In the cellForRowAtIndexPath each cell.uiTxtField.delegate is set to self.
The following happens both in the simulator and on the real iPhone device:
When I set the pointer/finger in the UITextField the keyboard pops up and
textFieldDidBeginEditing is triggered, that's fine and as expected.
When I leave the UITextField, textFieldDidEndEditing is triggered,
that's also fine and as expected.
But when I start to type text, the cursor stops blinking but no text
is typed to the UITextField.
I can copy and paste text by holding down the pointer/finger in a UITextField that contains text, select copy and then paste it in another UITextField (or the same).
The backspace works fine.
It also let's me type in symbols and smilies etc.
The only thing I can't type in is characters/letters and numbers
The return button doesn't trigger textFieldShouldReturn
Since textFieldDidBeginEditing and textFieldDidEndEditing is triggered I assume my delegate setup is fine, but I can't understand why I can't type text and why textFieldShouldReturn is not triggered.
This might be related.
Any help is appreciated.
have you put this in the "init" method of your custom class?
try putting a code like this in your implementation file...
#implementation CustomAlertClass <UITextFieldDelegate>
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//
self.YourTextField.delegate = self;
}
return self;
}
#end
Short answer: Make sure you don't have any code that messes with the 'editing' property on UITextField.
I had the same symptoms where I was definitely setting the delegate properly and textFieldDidBeginEditing and textFieldDidEndEditing were getting called, but textFieldShouldReturn and shouldChangeCharactersInRange were not getting called. I also could not type any characters, but I could copy paste into the text field. In my case I also happened to be putting the text fields inside cells in a UITableView. My situation was slightly different in that the delete button did not work.
Where I went wrong, was that I was not using a raw UITextField in my cells, I had my own subclass of UITextField. My subclass had a property 'isEditing', which I was modifying in the UITextFieldDelegate methods and used to figure out how to scroll the table view when the text field was selected. This was overriding the 'isEditing' method on UITextField with is used as the getter for the UITextField 'editing ' property. Once I got rid of my subclass isEditing property everything behaved as expected.

MonoTouch.Dialog: Setting Entry Alignment for EntryElement

Using the EntryElement to enter data as is results in the data being entered being aligned sort of in the middle.
How do I specify that the entry should be right aligned on an iPad.
For example:
Have you tried overriding CreateTextField on EntryElement ?
That should give you complete control on how to create the UITextField being used for the entry part of the element.
Update Notice that if you override CreateTextField, you should also override the Cellkey property, to ensure that this cell is not shared through the UITableView cell-sharing machinery with other EntryElements.
Of course you'll need to know the right size before being called (or delay settings some properties until you know for sure).

MonoTouch.Dialog: Dismissing a Keyboard

Using the Reflection API to auto generate a UI.
How can I dismiss the keyboard when the user selects a new field, or if they choose a field which generates a new view to pick from. In the later case, when the user returns to the first screen, the old keyboard is still there.
UIView.EndEditing(bool force);
The above will hide the keyboard for you without needing to know who the first responder is. I haven't done much with the reflection API but you should be able to call that on the view when an element is selected.
Apple Docs -- endEditing:
Clarification for those initially struggling with the MonoDialog portion of the question:
The EndEditing method is not available on DialogViewControllers objects directly (who inherit from UITableViewControllers). You should be calling EndEditing(bool) on the View of a DialogViewController and not trying to call EndEditing(bool) on the actual DialogViewController itself.
For clarification:
DialogViewController dc;
dc.View.EndEditing(true);
Note:
UIView objects include the EndEditing(bool) method, but UITableViewControllers do not inherit from UIView so the EndEditing method is not available on the controller itself. UITableViewControllers contain a view object, call EndEditing on that view object.
Check the ResignFirstResponder method. This one should help you I guess.

Resources