How to add UITableView to UIAlertView? - iphone

I create a class:
#interface myUITableViewController : UIViewController
{
NSArray *listData;
}
...
and later,I do so:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
myUITableViewController *myUITable = [[myUITableViewController alloc] init];
[alert addSubview:myUITable.view];
[alert show];
After running,the result is that the myUITable.view's size is bigger than alert.
Why?
Please tell me if you know.
Thank you!

UIAlert is not really meant to be used like that. You should make your own custom UIView and add whatever content you need in it (the table and buttons). Then handle how it shows and hide yourself.
Even if you manage to get it shown correctly chances are it might break in the future. In one of my apps i was showing an alert with a UITextField. I was making space for it by adding "\n" to the message. In later iOS versions this stopped working and it looked really awful...

Related

Simple iPhone jailbreak tweak not working

#import <UIKit/UIAlertView.h>
#class NSObject;
#interface SBIconController : NSObject
+ (SBIconController *)sharedInstance;
- (BOOL)isEditing;
#end
%hook SBIconController
-(void)iconTapped:(id)tapped {
SBIconController *sbic = [objc_getClass("SBIconController") sharedInstance];
if ([sbic isEditing]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Message" message:[NSString stringWithFormat:#"%#", tapped] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
%orig;
}
%end
Above is a simple tweak that I have created with Logos. For some reason after installing, nothing is working, I just can't figure out what the problem is and How can I solve this problem?
Other questions that I have are:
Why do we declare class like SBIconController when there's already a SBIconController class?
Why do we declare it as a subclass of NSObject?
Why don't we just type in SBIconController when we're calling the [SBIconController sharedInstance] instead of [objc_getClass("SBIconController") sharedInstance]?
Thanks a lot for your help!
The code is fine. I tested it (I don't use logos) and iconTapped: method is indeed called when you tap an app icon. But what are you trying to achieve with isEditing? This property indicates whether you are editing SpringBoard (tap and hold an app icon) and when it equals YES method iconTapped: is NOT called when icon is tapped. It's called only when isEditing equals NO. So I suggest you insert alert without if ([sbic isEditing]) to test whether your tweak is working.
As for your other questions:
When dealing with private APIs we don't have headers and will get warnings/errors if we try to use them. In your case it's SBIconController. To solve this problem we can either download headers that others dumped using various tools like class-dump or declare these private APIs yourself. In your case it's latter.
Because SBIconController inherits from NSObject.
You can do it either way. Of course, when you have class declaration you don't need to use objc_getClass. And in your case you don't even need either of this things. You can just use self like you would in any other obj-C method. Your code will look like this:
%hook SBIconController
-(void)iconTapped:(id)tapped {
if ([self isEditing]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Message" message:[NSString stringWithFormat:#"%#", tapped] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
%orig;
}
%end

UIAlertView crash by adding clickedButtonAtIndex

I create a class to call UIAlertview show on my screen. I write the UIAlert function in another class. Both these two classes are not my viewController class.
I use this UIAlert, which is a UITextfield inside, to store texts into a plist file.
here is the class to call UIAlert:
#import "Story.h"
#implementation Story
...
+ (void)stage1
{
AlertClass *pointer = [AlertClass new];
[pointer doAlert];
}
here is the class AlertClass.m file:
- (void)doAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
//this makes crash!
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
self.storyFlow.text = [alertView textFieldAtIndex:0].text;
}
Before I add UIAlertViewDelegate in the .h and override the method "clickedButtonAtIndex", it works great. However, I need to store some data from the UITextfield inside the alert view. I get crash and don't know the message it responds as following.
Please help me to solve this problem. Thanks.
[crash pic] https://dl.dropbox.com/u/47381923/crash.tiff
do an NSLog on the text you get back from the Alert View to see whether that is the crash or the subsequent 'self.storyFlow.text = ' is causing it. Perhaps self.storyFlow has not been created yet (with alloc/init)

Alert with UITableView

Is it possible to do something like what is shown below using an Alert with a UITableView? If so, how can it be done?
read my this post - http://www.makebetterthings.com/blogs/iphone/add-uitextfield-in-uialertview/
and try to add a table or scroll view instead of uitextfield
No, that's not a UITableView. If you want to show something like that, use UIAlertView:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Annuler" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil]; [alert show]; [alert release];

Xcode - Help implementing some code into a view based app?

Can someone help me with implementing this code into a view based app?
This is the code that I have:
- (void)webViewUIWebView *)newsweb didFailLoadWithErrorNSError *)error {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Connection Error1!" message:#"Please confirm network connectivity and try again!" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
With this code and any other code that I may need, but don't know, I would like to know what code to implement into the .h + .m view controller files.
What I am trying to achieve is an error after starting the app if there is no network connection available. What I'm worried about also but not quite sure if it will happen, is that this will repeat the error "x" times for how many UIViews I have. If that would be the case could you also help me should that it would only show the error once.
Put a Boolean in your header file, and when the alert fires, change it. If the Boolean is false, then simply don't show the alert.
#interface
BOOL alertShown;
#end
#implementation
-(void)applicationDidFinishLaunching{
alertShown = NO;
}
-(void)webViewError{
if(alertShown == NO){
//show the alert
alertShown = YES;
}
}
#end

iPhone SDK: how to get the value of a UITextField in an alert?

I'm really new at this. I've been working my way through a couple of "HelloWorld" type tutorials that basically have a text field, a button, and when you click the button it alerts whatever's in the text field. I've gotten as far as getting an alert to show and being able to set the title, message, and button text directly. However my attempts at getting the contents of my UITextField keep failing. I either get errors, no response, or just "(null)". My code's here.
#synthesize textField;
- (IBAction)btnClicked:(id)sender {
//text of textField
NSString *str = [[NSString alloc] initWithFormat:#"Hello, %#", textField.text];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello!"
message:str delegate:self
cancelButtonTitle:#"Done"
otherButtonTitles:nil];
[alert show];
[alert autorelease];
}
It looks like the textField property is not properly linked to the UITextField object you have in interface builder. Make sure your IBOutlets are set correctly.