UITextView Delegate shouldChangeTextInRange (or any over) doesn't get called - uitextview

I need to track changes in my UITextView method (actianly for limiting number of lines), but none of UITextViewDelegate methods are being called when editing in UITextView begins. Not even - (void)textViewDidChange:(UITextView *)textView;
I dont know what Im doing wrong
I added UITextViewDelegate method to header file like that:
#interface PirmasViewController : UIViewController <UITextViewDelegate, MFMa......
And I put any methods for tracking changes in my implementation file:
- (void)textViewDidChange:(UITextView *)textView{NSLog(#"something changed");}
- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText{
NSLog(#"something changed");
return YES;
}`
but no rezults.

I was missing one line of code:
UITextViewFieldName.delegate = self;

Related

FolderNameEditor not working with PropertyGrid

When using FolderNameEditor in my settings class, I cannot get it to display the ellipsis so I can change the folder. The code for my property is below.
Is there another attribute that I need? Change a setting on an existing attribute? Is there an alternative to FolderNameEditor, other than writing my own editor?
[Category("Schedule")]
[DisplayName("File Path")]
[Editor(typeof(FolderNameEditor), typeof(UITypeEditor))]
[ExpandableObject]
[UserScopedSetting()]
[DefaultSettingValue(#"c:\temp")]
public string ScheduleFilePath
{
get { return _scheduleFilePath; }
set { _scheduleFilePath = value; }
}
My settings class inherits from ApplicationSettingsBase. I have many other properties (fonts and colors) in my settings class and they work fine.
Specifying the FolderNameEditor seems to have no effect, I am only allowed to edit the property as a string. I tried the ExpandableObject property, but it just displays the length of the string.
Is there a decent alternative to PropertyGrid? I seem to spend an inordinate amount of time getting it to work.

Delete UITextView text

There is a reason why this method doesn't work?
-(void)textViewDidBeginEditing:(UITextView *)textView
{
textView.text = #"";
}
I just want that when I tap on UITextView, the text inside is canceled...
Thanks and have a nice day!
REPLACE:
OK. Here is what you need to do. First, in your class add the protocol:
#interface ClrssEditSearchVC : UITableViewController <UITextViewDelegate>
Then go into Interface Builder/Storyboard and Ctrl-drag from the UITextView to the source file and it will give you the option to create the event. Then add your code to the new method.
ADD:
Another thing with your current implementation. First, correction in terms. You are working with a UITextField (not UITextView). To get your original impl working:
First, be sure you you have added the protocol to your class.
#interface YourVC : UIViewController <UITextViewDelegate>
Second, in your viewDidLoad method, add the following:
self.myTextField.delegate = self;
Finally, your method sig needs to change to ("view" -> "field"):
-(void)textFieldDidBeginEditing:(UITextField *)textField

monotouch DialogViewController RefreshRequested "System.ArgumentException: You should set the handler before the controller is shown"

I have some problems with getting the RefreshRequested event to work in one of my ViewControllers that implements the DialogViewController:
public CustomViewController () : base (null, true) {
RefreshRequested += delegate {
...
ReloadComplete ();
};
}
I am calling the CustomViewController from another ViewController like this:
var dvc = new CustomViewController();
this.ActivateController(dvc);
The error message I get is "Toplevel exception: System.ArgumentException: You should set the handler before the controller is shown"
Any pointers of what I am doing from here? Thanks
It looks like you do not have a RootElement specified, i.e. it's set to null by your own constructor, so you get warned that the internal state is not ready to set the event.
You should create an empty RootElement with your constructor and, later, add stuff to it (using the property). That should allow you to set the event in your own constructor. E.g.
public CustomViewController () : base (new RootElement (String.Empty), true)
Any pointers of what I am doing from here?
In doubt you can always see the entire source code MonoTouch.Dialog in it's github repository.
From my testing, the only place that you can set the event handler is in the constructor of the ViewController, as that's the only place where you can rely on the fact that the TableView property is null. I've tried the suggestion above of setting the RootElement in the constructor, but then always seem to have a TableView object before I can set the event handler. The problem with setting the event handler in the constructor though is that I don't have any way of resetting the event handler after cleaning it up.

Passing A Delegate In prepareForSegue Method

I am having a problem passing an object from a TableView to a ViewController in an IOS app. I am using storyboard and have elected ARC and passing the delegate in my "prepareForSegue" method.
Here is my code in my TableView which segues via a push to another ViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NextViewController *vc = (NextViewController *)[segue destinationViewController];
vc.managedObjectContext = managedObjectContext;
if ([[segue identifier] isEqualToString:#"EditCategory"])
{
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// I get a red warning which states "Cast of 'NSInteger' (aka 'int') to 'Entity' is disallowed with ARC" on this line:
[vc setEntity:(Entity *)selectedIndex];
}
}
Does anybody have any suggestions for how I can pass my object from the TableView to the ViewController? I am new to programming and have tried various expressions but nothing seems to work.
The error you're getting has to do with types.
The class NextViewController apparently has a method called -setEntity: that takes an object of type Entity *. The error is because you're trying to give -setEntity: an argument of the wrong type. You're trying to give it an NSInteger (which is a number like 0, 5, -999), but it wants an Entity.
You're on the right track for passing data from the table view to the NextViewController. You just need to do one of the following:
pass an Entity to -setEntity: (does the Entity class perhaps
have a constructor that takes an NSInteger?)
add a method to NextViewController that takes an NSInteger, and call that instead of -setEntity:

Problem with UICustomSwitch,

I am using UICsutomSwitch for my application. When I try to create it, I am getting an exception like,
Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSArray objectAtIndex:]: index 2 beyond bounds for empty array'
My code is as follows,
UICustomSwitch.h
#import <Foundation/Foundation.h>
#interface UICustomSwitch : UISwitch
{
}
-(void)setLeftLabelText:(NSString *)labelText;
-(void)setRightLabelText:(NSString *)labelText;
#end
UICustomSwich.m
#import "UICustomSwitch.h"
#implementation UICustomSwitch
-(UIView *)slider
{
return [[self subviews ] lastObject];
}
-(UIView *)textHolder
{
return [[[self slider] subviews]objectAtIndex:2];
}
-(UILabel *)leftLabel
{
return [[[self textHolder] subviews]objectAtIndex:0];
}
-(UILabel *)rightLabel
{
return [[[self textHolder] subviews]objectAtIndex:1];
}
-(void)setLeftLabelText:(NSString *)labelText;
{
[[self leftLabel] setText:labelText];
}
-(void)setRightLabelText:(NSString *)labelText
{
[[self rightLabel]setText:labelText];
}
#end
View Controller:
UICustomSwitch* switchView=[[[UICustomSwitch alloc]initWithFrame:CGRectMake(200,5,90,30)]autorelease];
[switchView setLeftLabelText:#"F"];
[switchView setRightLabelText:#"M"];
[switchView addTarget:self action:#selector(genderAction:) forControlEvents:UIControlEventValueChanged];
[elementView addSubview:switchView];
I am getting exception at " return [[[self slider] subviews]objectAtIndex:2];" call. I don't know what is the wrong, Can you guys please suggest me on this.
Thanks in advance,
Sekhar.
I ran across this issue and found the answer here:Custom UISwitch Text
Basically in iOS 4, there were UILabel's in the UISwitch's subviews that represented the "On/Off" labels. In iOS 5, there are no UILabels in the subviews array (hence the array error you're getting). The above link offers an external class you can download and customize. In my opinion, it seems like Apple is discouraging customization of UISwitch. The functionality you're after could be accomplished another way (segmented control, simulated checkbox, etc).
Also, in the given link above, the author proposes that the issue might be with not including armv6. I tried this and it does not fix the problem.
The exception indicates you are attempting to access an element of the array that is out of bounds (in a place that is larger than the actual size of the array).
You can use breakpoints and/or NSLog() calls carefully placed in your code to determine if this array ever is not-empty, and if that is so, you can continue to use these calls to find out just where the array becomes empty.
Clearly if the array is empty then the switch is setup differently than you expect it to be.

Resources