Im using Parse.com to populate information in my app, and have a column set up for URLs called 'url' and this contains a simple url such as "http://www.google.com.
I pull in all my data on a table view and then when navigating to my detail view have a UI Button that i wish to pass the url value from parse.com into. So that when this is clicked,
the safari window on iphone launches and displays this site.
It the moment whatever i try does not work, ive tested displaying this value in a label to ensure im getting the right value from parse which i am. But this isnt passing to a UIButton.
the URL value is pulled in on the tableViewController with the below and pass through a segue,
listing.url = [object objectForKey:#"url"];
and then ive wired up a UIButton with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.co.uk"]];
which works with the hardcoded url, but i need to replace this URL with the correct URL from my parse.com data browser,
any help would be amazing,
thank you for taking the time in advance,
If listing is the [segue destinationViewController] from inside your prepareForSegue method, then listing.url will be storing the required URL inside your Detail View Controller.
So all you'd need to do from your Detail View Controller is:
- (IBAction)actionOpenWebpageOnSafari:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: self.url]];
}
Related
As the heading states when I click a button on my main view I need it to call a method in my controller for that view. Ive been trying for hours and Ive changed the specific lines of code many times but all variations seem to give the same errors so im just showing the simplest versions to get my point across. Everytime I try something I get a 404 error that the path is not found. So im assuming something is wrong with the code in my view. Im not using JQuery or any javascipt
The line of code in my index view:
#Html.ActionLink("Button4Pressed", "Button4Pressed", "HomeController");
I know this wont work for getting methods but it works for changing pages so I thought I would start there. Im not sure if I should be doing it as a href or button.
my method in my HomeController:
[HttpPost]
public ActionResult Button4Pressed()
{
state = "year";
MyChart();
return View();
}
heres my Solution Explorer
Im pretty new to MVC and propably doing some pretty stupid stuff so any help is appreciated thanks.
You have two options:
Option A
Remove the [HttpPost] attribute from your controller method and you will be able to create normal links to it, i.e. with #Html.ActionLink()
Option B
Keep the [HttpPost] attribute and use a form or ajax to send the request as a HTTP Post request, i.e.
<form id="Button4Pressed" action="#Url.Action("Button4Pressed", "Home")" method="post"></form>
Button4
I have set up a core data model and I would like the ability to be able to tap on an entry and have an blank email pop up with the core data contents included. here is my code for saving the data-
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:#"Device" inManagedObjectContext:context];
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
NSString *versionString = [NSString stringWithFormat:#"Minutes of %#", self.versionTextField.text];
[newDevice setValue:timetickNumber forKey:#"name"];
[newDevice setValue:versionString forKey:#"version"];
[newDevice setValue:self.companyTextField.text forKey:#"company"];
Thanks in advance!
You can't click (or tap) on a Core Data object, because they do not have any UI and do not respond to UI events. The general flow you want is probably something like:
Figure out what UI element should trigger the email action-- a button, or a table row, or whatever UI element you're using.
In the handler method for taps on that element, create the MFMailComposeViewController. Where this happens depends on what UI element you're using. If your UI element is a button, this happens in whatever method your button calls when tapped. If the UI element is a table row, you probably want to use tableView:didSelectRowAtIndexPath: in your table view's delegate.
In that same method, get a reference to the managed object you want to send. If you fetched it (or created it) earlier, you might already have an instance var that points to it. If not, you may need to fetch it here.
Before displaying the MFMailComposeViewController, configure either the message body (via setMessageBody:isHTML:) or the attachment (via addAttachmentData:mimeType:fileName:) to contain the data from your managed object's data
Display the mail compose view to the user.
I have a tab bar controller, one tab screen contains a web view, loading a request say google.com, when it is loading(ie before the didload delegate method call of webview), if I switch to another tab and then go back, the spinner is still running but the page is never loaded, I guess viewDidLoad is only called once, so should I put the loading code in viewDidAppear, or is there anyway to solve this?
Thanks!
I don't understand why you want to refresh the WebView everytime it appears. But use - (void)viewWillAppear:animated
Edit:
OK, since ive got more info now, i can give you more info!
In your .h:
BOOL *loaded
in your .m:
- (void)viewWillAppear:animated {
if (loaded == NO) {
//load the website
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[loaded setBool:YES];
}
- (IBAction)loadWebsite {
//if the user reloads or loads a new website do this:
[loaded setBool:NO];
//reload, or load the new website
}
To load, or reload your UITableView:
NSString *urlAddress = urltextfield.text;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Clarification: I am setting the BOOL to YES if the View is loaded, so when the webview has finished loading and the user switches to the other tab, and back the WebView doesn't get reloaded. But if the WebView isn't fully loaded the BOOl returns NO, and the WebView will get reloaded! When the WebView gets reloaded or a new Website gets loaded im setting the BOOL to NO, and that loops over and over! Note that BOOls are NO by default.
I have a window based applicaiton with tab bar and navigation bar integrated into it. On the navigation bar have a custom button which opens a table view.
On clicking on the cell of the table I want to open a new table view controller. But as soon as I click on the cell of first table I get an exception that
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'AddForm''
I have checked that AddForm is in right place.
I have tried all the solutions given above and on other thread, but still stuck. I hope someone can help me.
The flow is something like this
ListButton (on click opens a list view) -> a table view opens -> (on click of a cell should open a new table view Controller and fetch data from core data)
My root view controller code is in the second table view controller file... is that what I am doing wrong? I am doing so because I don't need the core data before that....
Please help
Thanks in advance
I Used to have the same problem first of all check in your AppDelegate.m class if the managedObjectContext is created
if it is created check if it is pass it as argument
something like this
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
if that is correct for you main view just be sure that you are passing it through your views something like this
self.detailViewController.managedObjectContext = self.managedObjectContext;
well at least that works for me =)
The most common cause of this problem is misspelling the name of the entity or getting the capitalization wrong. Check that AddForm is spelled exactly the same in the code and the data model editor.
I'm a Java programmer, but not a JavaScript programmer. I have just discovered YUI, and am trying to get started using it. What I'd like to try and do is have the query form at the top of the page, the user press Submit and the results show up in a YUI DataTable below the query form.
Normally, of course, on a HTML form the user presses Submit, the request gets sent to the server, and I use Struts to process it and then forward the request to a JSP and HTML gets sent back to the browser. That's what I do on a daily basis. With Ajax, I understand it's different in that I should return XML instead. Not a problem. Easy to do.
The questions I have deal with the YUI side of things. When the Submit button is pressed, what happens? Not normal form submission, right? Do I implement an onSubmit() JavaScript function which then triggers some YUI DataSource to go fetch the data? How do the request params get passed? Hopefully I don't have to construct the request manually. I'm guessing that I use a YAHOO.util.XHRDataSource and that's the DataSource for the DataTable.
I've managed to get the YUI DataTable to work using an HTML table element. Now I just need to switch it over to real data. Curiously, the YUI documentation seems a bit weak here, unless I'm missing something. Maybe this is just basic Ajax that the YUI docs don't cover?
First of all, when working with Ajax you don't need to return XML from the server, you could return plain text, XML, JSON strings, literally any form of textual data that you want. One example of populating a Datatable with JSON data is provided here:
http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html
An example of how to send a post request using Ajax and YUI is provided here.
http://developer.yahoo.com/yui/examples/connection/post.html
That should get you started, now just link both of them together.
To connect to the server you can use the Yahoo.util.Connect.asyncRequest method which takes in the following parameters:
static object asyncRequest ( method , uri , callback , postData );
See an example here, this one uses "GET" so you can use either "GET" or "POST" just make sure you pass in your parameters
http://developer.yahoo.com/yui/examples/json/json_connect.html
Once your function returns on your "onSuccess" do the following to parse the response text to JSON
try {
jsonData = YAHOO.lang.JSON.parse(o.responseText);
}
catch (x) {
alert("JSON Parse failed!");
return;
}
The "jsonData" object now contains your data, so now you can follow this example:
http://developer.yahoo.com/yui/examples/datatable/dt_basic.html
It shows you how to initialize a datatable with a local object holding the datasource. basically it would be something like this
var myColumnDefs = [
{key:"Column1Data", label:"Column1 Header" sortable:true, resizeable:true},
{key:"Column2Data", label:"Column2 Header" sortable:true, resizeable:true}
];
var myDataSource = new YAHOO.util.DataSource(jsonData);
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
myDataSource.responseSchema = {
fields: ["Column1Data","Column2Data"]
};
var myDataTable = new YAHOO.widget.DataTable("basic",
myColumnDefs, myDataSource, {caption:"DataTable Caption"});
For this to work, you have to have a "div" container in the HTML code with an id of "basic" note this matches the first parameter on the DataTable
Hope this helps