Im new here and am stumped trying to add a pull to refresh control to update my xml table view. I'm getting the proper pull to refresh animation, but the data is not refreshing. Please help.
- (void)viewDidLoad {
[super viewDidLoad];
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://www.PLACEHOLDER.rss.xml"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
UIRefreshControl *refreshControl = [UIRefreshControl new];
[refreshControl addTarget:self action:#selector(refresh:)
forControlEvents:UIControlEventValueChanged];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull
to refresh..."];
self.refreshControl = refreshControl;
}
- (void)refresh:(UIRefreshControl *)sender {
// ...refresh code
NSURL *url = [NSURL URLWithString:#"http://www.PLACEHOLDER.rss.xml"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
[sender endRefreshing];
}
Related
I am trying to initiate a call from my iphone app,and I did it the following way..
-(IBAction) call:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Call Besito" message:#"\n\n\n"
delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Submit", nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
NSString *phone_number = #"0911234567"; // assing dynamically from your code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phone_number]]];
NSString *phone_number = #"09008934848";
NSString *phoneStr = [[NSString alloc] initWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];
[phoneURL release];
[phoneStr release];
}
}
by the above code..I am able to successfully make a call..but when I end a call,I'm not able to return to my app
So, I want to know how to achieve,that..also please tell me how we can initiate a call using webview...
This is my code :
NSURL *url = [NSURL URLWithString:#"telprompt://123-4567-890"];
[[UIApplication sharedApplication] openURL:url];
Use this so that after call end it will return to app.
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:+9196815*****"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
Please try this it will definitely let you Back to Your App.
NSString *phoneNumber = // dynamically assigned
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
following code will not return to your app [no alertview will show before make call]
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#",phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
following code will return to your app "alertview will show before make call"
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#", phoneNumber]];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
You can also use webview, this is my code :
NSURL *url = [NSURL URLWithString:#"tel://123-4567-890"];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 150, 100)];
[self.view addSubview:btn];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(50, 50, 150, 100)];
webview.alpha = 0.0;
[webview loadRequest:[NSURLRequest requestWithURL:url]];
// Assume we are in a view controller and have access to self.view
[self.view insertSubview:webview belowSubview:btn];
[webview release];
[btn release];
It's not possible to return back to the app after ending a call because it's an app.
I have a method that loads data asynchronously.
-(void)loadingDataAsynchronously{
NSURL *url = [NSURL URLWithString:#"http://vbahrain.azurewebsites.net/api/yearapi"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSData *data = [[NSData alloc] initWithContentsOfURL:location];
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
self.yearBucket = [NSMutableArray array];
for (NSDictionary * dict in array) {
Year *year = [[Year alloc ]init];
year.yearName =[dict objectForKey:#"Year"];
year.speeches = [dict objectForKey:#"Speeches"];
[self.yearBucket addObject:year];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}];
[task resume];
}
This is the code that I'm using to load the MPProgressHUD.
- (void)viewDidLoad
{
[super viewDidLoad];
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.mode = MBProgressHUDModeDeterminate;
HUD.labelText = #"Loading";
HUD.delegate = self;
[HUD showWhileExecuting:#selector(loadingDataAsynchronously) onTarget:self withObject:Nil animated:YES];
}
The MPProgressHUD appears and vanishes in a second. How do I get to show the MPProgressHUD to display the actual progress on loading data in the background thread.
You can try to remove the HUD inside the loadingDataAsynchronously method.
- (void)viewDidLoad
{
[super viewDidLoad];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[self loadingDataAsynchronously];
});
}
-(void)loadingDataAsynchronously{
NSURL *url = [NSURL URLWithString:#"http://vbahrain.azurewebsites.net/api/yearapi"];
...
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
...
}
I am new to iphone development. I am able to use the data in connectiondidFinishLoading method.But i see "connection didfinishloading" method called twice.I don't know ,where i am going wrong. Here is my code
Edited code:
again connectionDidFinishLoading called twice
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if(textField==CompanyName)
{
autocompleteTableView.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
[self searchAutocompleteEntriesWithSubstring:substring];
return YES;
if([CompanyName.text length]==0)
{
autocompleteTableView.hidden = YES;
[popoverController dismissPopoverAnimated:YES];
}
}
return YES;
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring
{
data = [[NSMutableData alloc] init];
self.receivedData = data;
[data release];
NSURL *jsonUrl =[NSURL URLWithString:[NSString stringWithFormat:#"http://xxxx=%#",substring]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:jsonUrl];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self ];
//self.connection = connection;a
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
parser = [[NSXMLParser alloc] initWithData:receivedData];
currentHtmlElement=#"5";
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
[parser release];
if([arr4 count]!=0)
{
self.autocompleteUrls = [[[NSMutableArray alloc] init]autorelease];
UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
self.autocompleteUrls = [[NSMutableArray alloc] init];
viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake (410, 120,270, 250)];
autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,270,250) style:UITableViewStyleGrouped];
autocompleteTableView.delegate = self;
autocompleteTableView.dataSource = self;
autocompleteTableView.scrollEnabled = YES;
autocompleteTableView.backgroundColor = [UIColor lightTextColor];
autocompleteTableView.rowHeight=28;
autocompleteTableView.backgroundView = nil;
autocompleteTableView.backgroundColor = [UIColor whiteColor];
autocompleteTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[autocompleteTableView setSeparatorColor:[UIColor orangeColor]];
[viewForautoCompleteTableView setFrame:CGRectMake(210,380 ,autocompleteTableView.frame
.size.width
,autocompleteTableView.frame.size.height)];
[viewForautoCompleteTableView addSubview:autocompleteTableView];
[viewForautoCompleteTableView setBackgroundColor:[UIColor whiteColor]];
CGRect popoverFrame = viewForautoCompleteTableView.frame;
popoverContent.view = viewForautoCompleteTableView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate=self;
[popoverContent release];
[popoverController setPopoverContentSize:CGSizeMake(viewForautoCompleteTableView.frame.size.width, viewForautoCompleteTableView.frame.size.height) animated:NO];
[popoverController presentPopoverFromRect:popoverFrame inView:testscroll permittedArrowDirections:0 animated:YES];
[autocompleteUrls removeAllObjects];
for(int i=0;i<[arr4 count];i++)
{
NSString *curString = [[arr4 objectAtIndex:i] valueForKey:#"Name"];
[autocompleteUrls addObject:curString];
}
}
[autocompleteTableView reloadData];
[connection cancel];
}
you should remove [connection start]; because connection will start automatically after NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:selfstartImmediately:NO];
Edit
a valid NSURLConnection initialization
NSURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#""]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
I try this but not work I can hear the sound but I can't see the image..How can I solve this??
in app delegate class:
- (IBAction)tanitimVideo:(id)sender {
// create our UnifeyeMobileViewController and present it
video* unifeyeMobileViewController = [[video alloc] initWithNibName:#"video" bundle:nil];
unifeyeMobileViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentModalViewController:unifeyeMobileViewController animated:YES];
[unifeyeMobileViewController release];
}
in video.m class:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
Try using MPMoviePlayerViewController instead, very little code to get it working and you can do it all from your app delegate ;)
- (IBAction)tanitimVideo:(id)sender {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[self presentMoviePlayerViewControllerAnimated:mp];
[mp release];
}
Look at your .m file-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
////////// <<<<<>>>>>>>>>> //////////
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]
initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
why do you make 2 controllers (theMovie , moviePlayer) and you setting all in theMovie but running the moviePlayer.
it's should be like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"debutteaser" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie setShouldAutoplay:YES];
[self presentMoviePlayerViewControllerAnimated:theMovie];
}
hope it's help.
This piece of code:
- (IBAction) getXML {
goButton.enabled = NO;
[self performSelectorInBackground:#selector(parseInBackground) withObject:nil];
}
- (void)parseInBackground {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
xmlParser = [[XMLParser alloc] init];
NSURL *xmlurl = [[NSURL alloc] initWithString:#"http://www.mysite.com/myfile.xml"];
[xmlParser fetchXMLFromURL:xmlurl];
[self performSelectorOnMainThread:#selector(didFinishXMLParsing) withObject:nil waitUntilDone:YES];
[xmlurl release];
[pool drain];
}
- (void)didFinishXMLParsing {
goButton.enabled = YES;
}
triggers this code:
- (void)fetchXMLFromURL:(NSURL *)xmlurl {
XMLData = [[NSMutableData alloc] init];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:xmlurl];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
However, when I step through it in debug, as soon as it gets to '}' in fetchXMLFromURL it returns to the line:
[self performSelectorOnMainThread:#selector(didFinishXMLParsing) withObject:nil waitUntilDone:YES];
and the connection to the URL which fetches the XML never actually gets triggered. Anyone any idea why?
This revised version seems to be working correctly, can anyone spot any potential issues?
- (void)fetchXMLFromURL:(NSURL *)xmlurl {
XMLData = [[NSMutableData alloc] init];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
XMLData = [NSData dataWithContentsOfURL:xmlurl];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self startParsingXML];
}
- (void) startParsingXML
{
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:XMLData];
xmlParser.delegate = self;
[xmlParser parse];
[xmlParser release];
}
Revised again, hopefully correct now
- (void)fetchXMLFromURL:(NSURL *)xmlurl {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
XMLData = [[NSData alloc] initWithContentsOfURL:xmlurl];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[self startParsingXML];
}
- (void) startParsingXML
{
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:XMLData];
xmlParser.delegate = self;
[xmlParser parse];
[xmlParser release];
}
Yep. The NSURLConnection method you're using is asynchronous itself—it calls back to a couple of different delegate methods (as specified by the NSURLConnectionDelegate protocol) as it gets data. You might, in this case, be best off using the +sendSynchronousRequest:returningResponse:error: method, or NSData's +dataWithContentsOfURL:options:error:, as both of those will block execution on your background thread (which is fine) until they've finished getting your data. Also, make sure you set the network activity indicator's visibility before starting a synchronous request.
You're releasing the NSURLConnection as soon as you create it, which means it is immediately deallocated. You shouldn't release the NSURLConnection until you receive a delegate message that tells you the operation is complete, or has failed for some reason.