NSMutableDictionary doubts in iphone sdk - iphone

Ha ii,everybody ,i am doing a reader application ,in my app there is a note syncing option to googledoc,so the user write the note in a note-view and saved ,the saved note is displayed or saved in another view controller in UItableview .My requirement is when the user tapped the gDoc button it automatically wants to sync all the notes from the UiTableView to GDoc.I just saved the notes by this code when the save button pressed
-(IBAction)savedNote
{
[delegate.indexArray addObject:[NSString stringWithFormat:#"%# %#:%#",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
[delegate.notesArray addObject:textVieww.text];
[notes setValue:textVieww.text forKey:[NSString stringWithFormat:#"%# %#:%#",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]];
NSString *DataPath = [Malayalam_BibleAppDelegate getPath];
[delegate.data writeToFile:DataPath atomically:YES];
proAlertView *alert = [[proAlertView alloc]initWithTitle:#"NOTES" message:#"Notes Saved" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert setBackgroundColor:[UIColor colorWithRed:0.255 green:0.218 blue:0.185 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
[alert show];
[alert release];
}
-(IBAction)_clickbtngoogledocsync:(id)sender
{
Googledocmainpage *detailViewController = [[Googledocmainpage alloc] initWithNibName:#"Googledocmainpage" bundle:nil];
// Pass the selected object to the new view controller.
detailViewController.localStringtextnote = localStringtextnote;//i want to pass these note to googledocmainpage as localstring
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
UIView *langview = (UIView *)[self.view viewWithTag:120];
//ViewWithTag Number should be same as used while allocating
[langview removeFromSuperview];
/* [self.view addSubview:syncView];
UIView *popView = (UIView *)[self.view viewWithTag:106];
//ViewWithTag Number should be same as used while allocating
[popView removeFromSuperview];*/
}
How to do this.Thanks in advance.

Related

UITextView is not resigning when added as sub view of UIAlertView

I've added UITextView as a sub view of UIAlertView, I've added UIToolBar with a Done button (using UIBarButtonItem) as inputAccessoryView to allow user to resign keyboard`. It's just working fine in iOS6.0. And not in iOS5.0.
I've break point and checked in all the way I can, for reconfirming my self, I've made a sample project and checked the same in both the iOS versions, and the problem is same.
Here's the code, that's messing with me,
-(UIToolbar *)accessoryView
{
if (!accessoryView) {
accessoryView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44.0)];
UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(hideKeyBoard)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
accessoryView.items = [NSArray arrayWithObjects:flexibleSpace,btn, nil];
[accessoryView setTintColor:[[UIColor blackColor]colorWithAlphaComponent:0.5]];
}
return accessoryView;
}
-(IBAction) showAlertWithTextView: (id) sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 50, 320, 200)];
alert.title = nil;
alert.message = nil;
alert.delegate = self;
//textview I've added in .h file
textView = [[UITextView alloc] initWithFrame:alert.bounds];
textView.text = #"This is a UITextView";
textView.keyboardAppearance = UIKeyboardAppearanceAlert;
textView.editable = YES;
textView.inputAccessoryView = [self accessoryView];
[alert addSubview:textView];
[alert show];
}
- (void)hideKeyBoard {
[textview resignFirstResponder];
//[self.view endEditing:YES]; //this is also not worked
}
Here's list of steps I'm doing,
Showing Alert with Textview
Focus to Textview
Tap on Done button to resign TextView
Its not resigning in iOS5 but resigning in iOS6
Any idea? What's going wrong?
Actually your textview is not the first responder. The first responder is your alertView.
So you should try this....
[textField resignFirstResponder];
[alertView resignFirstResponder];
To use this code you must declare your alertView object in your.h file
I've solved it, as solution given by #iOS Developer, but as I've so many UIAlertView objects to handle, I've added a property of UIAlertView in delegate, and assigning it with the object of my alertview like this,
-(void)willPresentAlertView:(UIAlertView *)alertView
{
//set current alertview
[[AppDelegate sharedDelegate] setCurrentAlertView:alertView];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//will remove current alertview reference
[[AppDelegate sharedDelegate] setNilCurrentAlertView];
}
- (void)hideKeyBoard {
[textView resignFirstResponder];
//when need to resign UITextView, get current alertview object
UIAlertView *alertView = [[AppDelegate sharedDelegate] getCurrentAlertView];
if(alertView) {
[alertView resignFirstResponder];
}
}
In AppDelegate.m file,
#pragma mark - UIAlertView Resign
- (void) setCurrentAlertView:(UIAlertView *)alert{
self.alertObj = alert;
}
- (void) setNilCurrentAlertView {
self.alertObj = nil;
}
- (UIAlertView *)getCurrentAlertView {
return (UIAlertView *)self.alertObj;
}
As it is somewhat late but I am wondering that your code will not work in iOS7 or not as from iOS7 onwards UIAlertView is not allowing to add any subview (As you are adding UITextView as subview of UIAlertView).
If your requirement is not to compulsory using the UITextView then you can use UIAlertView with following configuration with default textfield in alert.
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"Message"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message show];
And you can get value of this textfield in delegate of UIAlertView like this,
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[alertView textFieldAtIndex:0].text;
}

UIAlertView title label strange background color issue

First I show the UIAlertView like this in my view controller (really nothing fancy at all):
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thank you"
message:#"Successfully saved bookmark"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
But as you can see in the screenshot, the title label is taking the background of my view as its background color:
I have not even the slightest idea of where this could come from, here is how I style my view controller when it appears:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = #"Details";
[self.view styleBackgroundColor];
[self.saveToBookmarks configureButtonStyle];
[self.getDirections configureButtonStyle];
self.name.text = [simoItem name];
self.relativeLocation.text = [self relativeLocationStringForLocation:[simoItem location]];
self.address.text = [simoItem address];
self.type.text = [self buildTypesString];
[self.name styleMainLabel];
[self.address styleSubLabel];
[self.type styleSubLabel];
[self.relativeLocation styleSubLabel];
}
Tried cleaning the project, uninstalling the app from the sim and shaking my computer but nothing has done it so far...
EDIT: added code for styleMainLabel on request
-(void) styleMainLabel {
//colors
UIColor *backgroundColor = [Utilities getBackgoundColorPreference];
UIColor *textColor = [Utilities getTextColorPreference];
[self setBackgroundColor:backgroundColor];
[self setTextColor:textColor];
//text size styling
self.font = [UIFont fontWithName:#"Tiresias PCfont" size:35.0];
self.adjustsFontSizeToFitWidth = YES;
}
Okay I fixed the problem, this was cause by some CALayer color properties set in accessibility events callbacks. Here is the code that causes the problem
- (void)accessibilityElementDidBecomeFocused {
[super accessibilityElementDidBecomeFocused];
CALayer *layer = [self layer];
layer.backgroundColor = [[Utilities getFocusedBackgroundColorPreference] CGColor];
}
-(void) accessibilityElementDidLoseFocus {
[super accessibilityElementDidLoseFocus];
CALayer *layer = [self layer];
layer.backgroundColor = [[Utilities getBackgoundColorPreference] CGColor];
}
I haven't fixed it yet but turning off accessibility made it disappear. Thanks for your help.
There may be problem in styleMainLabel code. So first check your code and again if you are getting then do it.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thank you"
message:#"Successfully saved bookmark"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
UILabel *theTitle = [alert valueForKey:#"_titleLabel"];
[theTitle setBackgroundColor:[UIColor clearColor]];

I want to display UIProgressView on UIAlertView

I want to display UIProgressView on UIAlertView for displaying the processing of uploading of the file. But I have searched too much and also find on that link but sill unable to do that. I don't get idea from this
If anyone know the easiest way to do that then please let me know.
I've had problems doing this, and ended up with this:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[av setValue:progressView forKey:#"accessoryView"];
[av show];
Try this code...
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];
While this doesn't quite answer your question, try MBProgressHud, a third-party control that has this feature built-in. The examples supplied on Github should get you up to speed pretty quickly.
Try this code. Put YES for activity indicator and NO for progressView
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: #"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
Why not make use of the alerviewdelegate method
- (void)willPresentAlertView:(UIAlertView *)alertView
The advantage of this is we can see what size the alertview will actually be on screen, as iOS has precomputed this at this point, so no need for magic numbers - or overriding the class which Apple warn against !
And as of iOS7 I remember reading some document from Apple saying not to hard code any frame sizes but to always compute them from the app, or something along those lines ?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
To pull reference to the loading bar in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Then use
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
Remember to have defined
#import <objc/runtime.h>
static char myKey;
At the top of your class declaration
This is create a alert view
UIAlertController* alert=[UIAlertController alertControllerWithTitle:#"Message" message:#"This is test" preferredStyle:UIAlertControllerStyleAlert];
now add textfield
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder=#"Enter Text label";
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.backgroundColor=[UIColor whiteColor];
}];
and added it on view
[self presentViewController:alert animated:YES completion:nil];

iphone-UIAlertview-UIIndicatorview

i Am New In Iphone development. i have one form in which for display data I am calling a webservice. When that service is called it parses from other file, And Page Navigates To 'Send Page' In Which These Data Is Displayed In a UITableview.
i am also using uiAtertview And UIIndicatorview Both For Displaying that the process is going. But Problem Is When I Click On Button I Call UIAtertView + UIIndicator But It Is Not getting Displayed And Data is Also Not getting Displayed,,,
My Code Is
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Configuring Preferences\nPlease Wait.." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil,nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
self.ResultPage = [[ResultPage alloc] init];
self.title=#" Search ";
// Here My Webservice Is Call From Another ViewController Class And That Class Display Data //InTo UITableVIew
[self.ResultPage GetSearchResult:StrBookId : txtFPrice.text :txtTprice.text];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[self.navigationController pushViewController: _ResultPage animated:YES];
Please Suggest Me....
Thanx
You can add activity indicator in alert view and show that alert view when you call web service.I also do the same when I call webservice. it locks the view so that the user cannot click anything and look wise also seems to be fine and indicating user that something is going in process.
in .h file
UIAlertView *progressAlert;
in .m file
-(void)showAlertMethod
{
NSAutoreleasePool *pool1=[[NSAutoreleasePool alloc]init];
progressAlert = [[UIAlertView alloc] initWithTitle:#"Uploading please wait...\n" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
CGRect alertFrame = progressAlert.frame;
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.frame = CGRectMake(135,alertFrame.size.height+55, alertFrame.size.width,30);
activityIndicator.hidden = NO;
activityIndicator.contentMode = UIViewContentModeCenter;
[activityIndicator startAnimating];
[progressAlert addSubview:activityIndicator];
[activityIndicator release];
[progressAlert show];
[pool1 release];
}
-(void)dismissAlertMethod
{
NSAutoreleasePool *pool2=[[NSAutoreleasePool alloc]init];
[progressAlert dismissWithClickedButtonIndex:0 animated:YES];
[pool2 release];
}
call the method according to your requirements.
I call the methods in this way:-
[NSThread detachNewThreadSelector:#selector(showAlertMethod) toTarget:self withObject:nil];
[NSThread detachNewThreadSelector:#selector(dismissAlertMethod) toTarget:self withObject:nil];

How do I get text from UITextField in an UIAlertView

I'm trying to add a new cell to a tableview, and pop up an alert with a UITextField to allow the user to input the title they wish to give the new cell. I have code to pop up an alert with a UITextField when the "+" button is pressed, and the code to add a new cell, however I don't know how to get the text from the UITextField to insert it into the cell's title.
This is my code to pop up the alert:
UIAlertView* alertPopUp = [[UIAlertView alloc] init];
[alertPopUp setDelegate:self];
[alertPopUp setTitle:#"Enter event title"];
[alertPopUp setMessage:#" "];
[alertPopUp addButtonWithTitle:#"Cancel"];
[alertPopUp addButtonWithTitle:#"OK"];
UITextField * eventNameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[eventNameField setBackgroundColor:[UIColor whiteColor]];
[alertPopUp addSubview:eventNameField];
[alertPopUp show];
and my alertView action is:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if([buttonTitle isEqualToString:#"Cancel"]) {
return;
}
else if([buttonTitle isEqualToString:#"Ok"]) {
}
}
What can I do to get the text from eventNameField when "Ok" is pressed and add it to a mutablearray named eventList? Thanks!
Set the tag on eventNameField to something meaningful
eventNameField.tag = 1001;
Then inside of the alertViewDelegate you can get the TextField by using - [UIView viewWithTag:]
UITextField* textField = (UITextField*)[alertView viewWithTag:1001];
eventNameField.text should give you the value
//declare the array
NSMutableArray* eventList = [NSMutableArray array];
//set its value
[eventList addObject:eventNameField.text];
DHamrick probably has the better solution, but found one more that could work.
You can get all the subviews inside alertView with [alertView subviews] (returns a NSCFArray), then you just have to find the one that is of class UITextField, in your case you could get it with:
[[[alertView subviews] objectAtIndex:4] text]
The old answers don't take advantage of changes in UIAlertView.
In iOS 5 and beyond, there is an easier way of using UITextfield on an alert view:
UIAlertView *alertPopUp = [[UIAlertView alloc] initWithTitle:#"Enter event title" message:#"" delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
alertPopUp.alertViewStyle = UIAlertViewStylePlainTextInput;
self.alertTextField = [message textFieldAtIndex:0];
self.alertTextField.keyboardType = UIKeyboardTypeAlphabet;
alertPopUp.delegate = self;
[alertPopUp show];
[self.alertTextField becomeFirstResponder];
where alertTextField was set up like this:
#propery (nonatomic, strong) UITextField *alertTextField;
Then you can access alertTextField in your delegate response:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if([buttonTitle isEqualToString:#"Cancel"]) {
return;
}
else if([buttonTitle isEqualToString:#"Ok"]) {
NSLog(#"your text string is %#", self.alertTextField.text);
}
}
You could also just give the alertView a unique tag, and compare tag numbers, rather than save a reference to it using #property.