I wrote a tweak for cydia, but it does not seem to be working. I created the template using Theos. I got a header dump from the iosod tool, and found
`$` - (void)searchBarTextDidBeginEditing:(id)searchBarText;
inside of the SBSearchController class. Here is the code I have in the Tweak.
%hook SBSearchController
- (void)searchBarTextDidBeginEditing:(id)searchBarText
{
%orig;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Tweak"
message:#"Testing is running!"
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];`
}
%end
and my Makefile looks like this
include theos/makefiles/common.mk
Testing_FRAMEWORKS = UIKit
TWEAK_NAME = Testing
Testing_FILES = Tweak.xm
include $(THEOS_MAKE_PATH)/tweak.mk \
Everything compiles and installs correctly, but at runtime, when I tap on the search bar, and begin to type, nothing happens. Does anybody know what I did wrong?
Thanks!
Remember that since this is a delegate method it won't be called unless the delegate class implements the method. Have you tested this on an application which handles this event?
Try adding some logging to a file so you can see whether your code is being called or not.
Related
I just want to show some text on the UIAlertView but it is showing "Null" string if the text length larger than allowed size.
I am pretty sure the text will not larger than the screen (about a bit more than half), so I don't want to make it be complicated to implement a ScrollView for that.
I follow problem in changing size of uialertview to change the size of AlertView, but it does not work, additionally produce some weird visual effect.
I tried this third part component https://github.com/inamiy/YIPopupTextView, I can't even pass the compilation. (already import that 4 files into project.) I don't know why.
So, actually I just want to increase the size of text that allowed to show on AlertView. Any idea?
I wrote a tiny test program. Here's the only thing I added to the Single View Application template:
- (void)viewDidAppear:(BOOL)animated {
NSMutableString *message = [[NSMutableString alloc] init];
while (message.length < 100000) {
[message appendString:#"Hello, world! "];
}
[message appendString:#"This is the end."];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Test" message:message delegate:nil cancelButtonTitle:#"Done" otherButtonTitles:nil];
[alert show];
}
This works fine on the iPhone simulator running iOS 5.0, and on my iPhone 5 running iOS 6.0.2. All the text is displayed (in a scrollable text view).
Your problem is probably not with the size of the text.
I found a strange behavior while I was showing the result of a JSON object parsed in a dictionary and then printed on on an alertView (on Xcode 5.1.1, compiling for iOS 7.1 on iphone 64 bit simulator). For the same inputData:
[[UIAlertView alloc]initWithTitle:#"something" message:[[[NSString stringWithFormat:#"json:%#",[inputData dictionaryRepresentation]] stringByReplacingOccurrencesOfString:#" "withString:#""]substringToIndex:7035] delegate:self cancelButtonTitle:#"ok" otherButtonTitles: nil];
correctly prints, but if I say "substringToIndex:7036" it shows only blank space...without "stringByReplacingOccurrencesOfString:" method the limit is far beyond:
[[UIAlertView alloc]initWithTitle:#"something" message:[[NSString stringWithFormat:#"json:%#",[inputData dictionaryRepresentation]] substringToIndex:13768] delegate:self cancelButtonTitle:#"ok" otherButtonTitles: nil];
correctly prints, instead "substringToIndex:13769" not prints...I realize that is not a matter of maximum length but of special characters inside the JSON object
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"HELOOOOOOOO" message:#"write a number of text-lines/paragraph here"
delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:#"Yes", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 95, 260, 25)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
If you look close you will find that the message attribute is quite long. I need this alertview to first display the title, and then my long message, and then the text field and finally the 2 buttons.
But what hapence here, is that since the message is too long, the textfield overlaps with the buttons.
How can i solve this ?
If this is for iPhone, you really can't. The UIAlertView is not meant to handle input. Extended messages are shown with a scroll view but you really should not add a UITextField to it's view hierarchy (for one, it goes against their design standards and your app MAY get nixed!).
In this situation, it would probably be best to use a new UIViewController to handle showing your content.
Again, the only "actions" that UIAlertView is meant to provide is that of the multiple buttons.
Implement this piece of code in your implementation file.
- (void)willPresentAlertView:(UIAlertView *)alertView
{
alertview.frame = CGRectMake(12, 95, 260, 25); //You can set a frame that suits to your needs
}
This delegate - (void)willPresentAlertView:(UIAlertView *)alertView will invoke before showing the alerview, so it is a better way to set frame to your alertview.
For more informations on aleert views:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/occ/intf/UIAlertViewDelegate
Actually, it doesn't matter how long your message is. The alert view will always size so it fits.
One way you can fix this is by adding a bunch of \n at the end of your message string, which is equivalent to putting a line break.
EDIT: If your message is so long that it puts it in a UIScrollView, there's nothing you can really do unless you're fine with major hacking (aka, changing the bounds of the UIAlertView, moving each button down, etc.).
A second way works only on iOS 5 and newer. You can set the UIAlertView's alertStyle property to UIAlertViewStylePlainTextInput which will display an alert view with a text field.
Use newline or line break character \n for this:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"AlertView"message:#"\nhello:.................... \nwrite here.................. \nwrite here....................." delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:#"Yes", nil];
[alert show];
[alert release];
Check this blog post for more help
I am making a registration form, in which I have 8 text fields and one submit button.
Whenever the user fails to enter one of the text fields, upon click of submit button an error message should be generated.
And when the user fills all the text fields, on click of submit button it should go to the next page.
Please give me some advice, thanks.
Simple logic, in your Submit action check that your textField.text is not nil or empty (#""). If not textField.text show UIAlert. Like this
-(IBAction) submitButton
{
if(self.txtName == nil || [self.txtName.text isEqualToString:#""])
{
[self showErrorAlert];
}
if(self.txtEmail == nil || [self.txtEmail.text isEqualToString:#""])
{
[self showErrorAlert];
}
}
// and show error alert as
-(void) showErrorAlert
{
UIAlertView *ErrorAlert = [[UIAlertView alloc] initWithTitle:#""
message:#"All Fields are mandatory." delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[ErrorAlert show];
[ErrorAlert release];
}
-(void)emptyTextfieldVaildation
{
if( ([TxtFieldName.text isEqualToString:#""]) || ([TxtFieldPaswrd.text isEqualToString:#""]) )
{
UIAlertView *ErrorAlert = [[UIAlertView alloc] initWithTitle:#"Error!!"
message:#"Please fill in the details." delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[ErrorAlert show];
[ErrorAlert release];
}
else
{
// Action to be called on Submit button touch
}
}
Set the method on click of submit button
-(IBAction)submit:(id)sender
{
//Do all the textField Validation
}
Check the all textfield data by using
[textfield.text isEqualToString:#""]
put this into if statement for all text field.. If condition is true , then show alert View
You have to check all fields before, and there are several way to do this. You can control the lenght of text of each field and show an alert if some field is empty. You can check the length property of the NSString, so you can also operate on the length(e.g the password must be 8 char, otherwise Alert.).
If you have tagged these 8 textFields(or if you know that there are just this textfields in your view) a good way may be like this:
for(UITextField * tf in [self.view subviews]){
if(![tf.text length]>0){
//show the alert
}
}
hope this helps.
Last night I struggled with this too and I used
if ([myTextField.text length] == 0) {
// error code to handle empty text field.
}
to handle empty text field. It works, for empty text field, of course, but failed if there are some spaces in there. Some people in SO give suggestion to trim the string first before evaluate using the code above. See link
How to enable a UIButton if a textfield is not empty?
set tag property of all your text fields uniquely and access them using if(textFieldName.tag==*yourtag*) in button action event...
I am new to objective C, So maybe there is some basic thing that I am missing about selectors. I would like to understand the basic concept behind this error as I have not found an general error reference.
I am getting this error when using:
[CloseButton addTarget:PageContents action:#selector(CloseButtonPressed) forControlEvents:UIControlEventTouchUpInside];
and then later:
- (void)CloseButtonPressed:(id)sender{
UIAlertView *someError = [[UIAlertView alloc] initWithTitle: #"Comment" message: #"hello" delegate: self cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[someError show];
[someError release];
}
A couple suggestions that will help your code follow writing conventions used by all Objective C applications, and make your code more easily readable to others:
Object instances should be lower case, i.e. closeButton and not CloseButton, and pageContents, not PageContents
Method names should be lower case, i.e. -closeButtonPressed: and not -CloseButtonPressed:
To answer your question, you need to fix the action you are adding:
[CloseButton addTarget:PageContents action:#selector(CloseButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
That colon character (:) makes sure the sender gets through to -CloseButtonPressed:
As CloseButtonPressed takes parameter you should create selector using: #selector(CloseButtonPressed:)
I'm currently in the process of developing an app for the iPhone. There is a screen which requires users to enter their data in text format but it can easily be skipped by simply clicking the 'submit' button. Is there a way I can make these text fields required?
Have you tried de-activating the button unless the text field has something in it?
u can tell the button process to keep an eye on the text field so that if the text field is empty, the button wont process the function it would be like this
-(IBAction) buttonPressed:(id) sender
{
//----this will process the button function if the textfield is not empty
if(textField.text != #"")
{
>>> do the process <<<
}
else
//----this will show an alert message when the user tries to click button without filling the textfield
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"error"
message:#"please fill the information first"
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}