- (void)viewDidLoad {
webCollectionOnScroller=[[NSMutableArray alloc] init];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 370, 320, 94)];
scroll.pagingEnabled = YES;
currentWeb=0;
globali=0;
firstTime=0;
[loadingWeb startAnimating];
alertForLoading = [[UIAlertView alloc] initWithTitle:#"Loading..." message:#"link is being loaded.\n Please wait!" delegate:self cancelButtonTitle:#"Back" otherButtonTitles:nil];
[alertForLoading 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(alertForLoading.bounds.size.width / 2, alertForLoading.bounds.size.height - 100);
[indicator startAnimating];
[alertForLoading addSubview:indicator];
[NSThread detachNewThreadSelector:#selector(initializeParser)toTarget:self withObject:nil];
[super viewDidLoad];
}
and this is the console error "-[linksGallery respondsToSelector:]: message sent to deallocated instance 0x639a890
[Switching to process 2211]
"
It doesn't crash when I comment release statement on main view
-(IBAction) goToLinks{
linksGallery *showLinks=[[linksGallery alloc] initWithNibName:#"linksGallery" bundle:nil];
[self.navigationController pushViewController:showLinks animated:YES];
//[showLinks release];
}
Try with putting the below line at first:
[super viewDidLoad];
inside the "dealloc()" function:
[super dealloc];
at the end of all releases.
Hope this will help you.
That error message means the instance of linksGallery has been released by the time you send it the message 'respondsToSelector'. To debug this try also setting it to null when you release it, then it won't crash, although it probably won't do what you want either.
Try out following codes
-(IBAction) goToLinks{
linksGallery *showLinks=[[linksGallery alloc] initWithNibName:#"linksGallery" bundle:nil];
[self.navigationController pushViewController:[showLinks mutableCopy] animated:YES];
[showLinks release];
}
or
-(IBAction) goToLinks{
linksGallery *showLinks=[[[linksGallery alloc] initWithNibName:#"linksGallery" bundle:nil] autorelease];
[self.navigationController pushViewController:showLinks animated:YES];
//[showLinks release];
}
Hope this will help
Make your ViewDidLoad look like this :
- (void)viewDidLoad {
[super viewDidLoad];
webCollectionOnScroller=[[NSMutableArray alloc] init];
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 370, 320, 94)];
scroll.pagingEnabled = YES;
currentWeb=0;
globali=0;
firstTime=0;
[loadingWeb startAnimating];
alertForLoading = [[UIAlertView alloc] initWithTitle:#"Loading..." message:#"link is being loaded.\n Please wait!" delegate:self cancelButtonTitle:#"Back" otherButtonTitles:nil];
[alertForLoading 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(alertForLoading.bounds.size.width / 2, alertForLoading.bounds.size.height - 100);
[indicator startAnimating];
[alertForLoading addSubview:indicator];
[NSThread detachNewThreadSelector:#selector(initializeParser)toTarget:self withObject:nil];
}
Related
I am trying to display an activity indicator in full screen so the user cannot press any button in the screen till the activity indicator is turned off as the alert view process. I have called the [activityView startAnimating] but I can push the buttons in the back. Is there way to prevent that?
Thanks from now.
You can use MBProgressHUD for such loading indictators. It's a great MIT-licensed class that extends well if you want to customize it further.
you can try this
UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
and add this line where you want remove your alert
[alert dismissWithClickedButtonIndex:0 animated:YES];
I'll suggest a best way will be displaying an alertView with activity indicator on the screen.
You can use the following code for this:
declare property for UIAlertView like:
#property (nonatomic, strong) UIAlertView *sendAlert;
self.sendAlert = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act setFrame:CGRectMake(115, 60, 50, 50)];
[act startAnimating];
[sendAlert addSubview:act];
act = nil;
[sendAlert show];
When you want to remove alert you can use:
[sendAlert dismissWithClickedButtonIndex:0 animated:YES];
sendAlert = nil;
Another alternative, you can add the activity indicator to your view itself and set the userInteraction of backbutton to false. When you finish the task set to True. But It won't be a nice way.
hey for your this requirement use the bellow code which you can access in your every view use..
add this bellow code and object in AppDelegate.h file like bellow..
UIView *activityView;
UIView *loadingView;
UILabel *lblLoad;
and paste this bellow code in AppDelegate.m file
#pragma mark - Loading View
-(void) showLoadingView {
//NSLog(#"show loading view called");
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor darkGrayColor];
loadingView.alpha = 0.5;
UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
subloadview.backgroundColor=[UIColor blackColor];
subloadview.opaque=NO;
subloadview.alpha=0.8;
subloadview.layer.masksToBounds = YES;
subloadview.layer.cornerRadius = 6.0;
lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
lblLoad.text=#"LoadingView";
lblLoad.backgroundColor=[UIColor clearColor];
lblLoad.textColor=[UIColor whiteColor];
[subloadview addSubview:lblLoad];
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[subloadview addSubview:spinningWheel];
[loadingView addSubview:subloadview];
[spinningWheel release];
}
[self.window addSubview:loadingView];
//[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}
-(void) hideLoadingView {
if (loadingView) {
[loadingView removeFromSuperview];
[loadingView release];
loadingView = nil;
}
}
and call this method when you want in any class , just like bellow..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];
Add a UIView above your current view when activity indicator starts :
UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.navigationController.view addSubview:overlayView];
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];
Since i am new in iPhone i am having a litle problem. I want to use UIActivityIndicatorView in my application. Since I have bee succesfull using indicatorView but I want to display the IndicatorView with a Blur Background so that i could not click on the button on my Current activity.
Please Friends
Guide me to some tutorial or some code.
Thanks a bunch in advance
Here you go this is my implementation but you can modify. Post the code in app Delegate and use anywhere in you application.
#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
First, you have to add a view with a black background and alpha of 0.3 or something. Then add the activity indicator above the view.
// an example
[self.view addSubview:aSemiTransparentBlackView];
[self.view addSubview:activityIndicator];
can try this also:
-(UIAlertView *)showActivityIndicator :(NSString *)message
{
alertViewProgress = [[UIAlertView alloc] initWithTitle:message message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *activity =[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(120,50,37,37)];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[activity startAnimating];
[alertViewProgress addSubview:activity];
[activity release];
[alertViewProgress show];
return alertViewProgress;
}
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];
#import "PantryLocator.h"
#import "RootViewController.h"
#import "CustomView.h"
#import "PantriesViewController.h"
#import "LafoodbankAppDelegate.h"
#implementation PantryLocator
#synthesize mymapView , activityIndicator , indexRow , cityName , customButton;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[self setCityName];
[super viewDidLoad];
}
-(void)setCityName
{
app5 = (LafoodbankAppDelegate *)[[UIApplication sharedApplication] delegate];
pantryDetail = [app5.cities objectAtIndex:indexRow];
cityName.frame = CGRectMake(80, 240, 150, 15);
[cityName setTitle:pantryDetail.cityName forState:UIControlStateNormal];
//[self setCustomButton];
}
/*-(void)setCustomButton
{
//To set custom button
customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setImage:[UIImage imageNamed:#"go-button-green.png"] forState:UIControlStateNormal];
[customButton addTarget:self action:#selector(goOnPantriesViewController:) forControlEvents:UIControlEventTouchUpInside];
[customButton setFrame:CGRectMake(272, 239, 20, 21)];
[self.view addSubview:customButton];
}*/
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[textField release];
return YES;
}
-(IBAction)backHome:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
-(IBAction)selectCity:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
[actionSheet showInView:self.view];
actionSheet.frame = CGRectMake(0,225,320,200);
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
CustomView *myView = [[CustomView alloc]initWithNibName:#"CustomView" bundle:nil];
[actionSheet addSubview:myView.view];
[actionSheet release];
//myView.view.frame = CGRectMake(0, 0, 320,100);
//[myView release];
/*UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, 40, 0, 0)];
pickerView.showsSelectionIndicator = YES;
pickerView.delegate = self;
pickerView.dataSource = self;
[actionSheet addSubview:pickerView];
[pickerView release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
//[actionSheet release];*/
}
-(IBAction)parsingCity:(id)sender
{
//Reading file from URL
NSURL *url = [[NSURL alloc]initWithString:#"http://www.lafoodbank.org/pantry-xml.aspx?city=all"];
NSData *data = [[NSData alloc]initWithContentsOfURL:url];
//Parsing
parser = [[PantryParser alloc]init];
[parser parseXML:data];
[data release];
}
-(IBAction)goOnPantriesViewController:(id)sender
{
PantriesViewController *pantriesViewController = [[PantriesViewController alloc]initWithNibName:#"PantriesViewController" bundle:nil];
[self.navigationController pushViewController:pantriesViewController animated:YES];
[pantriesViewController release];
}
-(IBAction)goToDesignsite:(id)sender
{
DesignWebView *designWebView = [[DesignWebView alloc]initWithNibName:#"DesignWebView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:designWebView animated:YES];
[designWebView release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)dealloc
{
[super dealloc];
}
#end
In above code i am confused that i am not go to next view when i select a particular city in setCityName so please give me solution.....
Instead of
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
Try This.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Your Title" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
Hope it helps.
hi friend
Go to your nib file and add method to your button first