Search Results

Search found 24043 results on 962 pages for 'private methods'.

Page 69/962 | < Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >

  • Stop scrolling to top in UIWebView - iPhone

    - by sagar
    I have placed following javascript in my html file. <script TYPE="text/javascript"> function srk(){ document.ontouchmove = function(e){ e.preventDefault(); } } </script> I am scrolling my webview by following code with some animation. [myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: @"window.scrollTo(0,%i);",414*self.initialScrollPosition]]; Everything going right, but on problem that I am facing is as follows. Whenever User/I tap on the status bar of iPhone, WebView Bydefault scrolls to top. This should not be done. Is it possible to prevent inbuilt functionality ? I know one of the option is as follows. ((UIScrollView *)[[myWebView valueForKey:@"_internal"] valueForKey:@"scroller"]).scrollsToTop = NO; But is it valid to do ?

    Read the article

  • Scoping inside Javascript anonymous functions

    - by DCD
    I am trying to make a function return data from an ajax call that I can then use. The issue is the function itself is called by many objects, e.g.: function ajax_submit (obj) { var id = $(obj).attr('id'); var message = escape ($("#"+id+" .s_post").val ()); var submit_string = "action=post_message&message="+message; $.ajax({ type: "POST", url: document.location, data: submit_string, success: function(html, obj) { alert (html); } }); return false; } Which means that inside the anonymous 'success' function I have no way of knowing what the calling obj (or id) actually are. The only way I can think of doing it is to attach id to document but that just seems a bit too crude. Is there another way of doing this?

    Read the article

  • Invoke method in another class

    - by Sam
    I have two view controllers (viewControllerA and viewControllerB) with their own views. When the user touches a button in the view of viewControllerA, I am able to load the view of the viewControllerB. However, I don't know how to invoke a method in viewControllerB's class!

    Read the article

  • How do I make PHP's Magic __set work like a natural variable?

    - by Navarr
    Basically, what I want to do is create a class called Variables that uses sessions to store everything in it, allowing me to quickly get and store data that needs to be used throughout the entire site without working directly with sessions. Right now, my code looks like this: <?php class Variables { public function __construct() { if(session_id() === "") { session_start(); } } public function __set($name,$value) { $_SESSION["Variables"][$name] = $value; } public function __get($name) { return $_SESSION["Variables"][$name]; } public function __isset($name) { return isset($_SESSION["Variables"][$name]); } } However, when I try to use it like a natural variable, for example... $tpl = new Variables; $tpl->test[2] = Moo; echo($tpl->test[2]); I end up getting "o" instead of "Moo" as it sets test to be "Moo," completely ignoring the array. I know I can work around it by doing $tpl->test = array("Test","Test","Moo"); echo($tpl->test[2]); but I would like to be able to use it as if it was a natural variable. Is this possible?

    Read the article

  • Why does the Java Collections Framework offer two different ways to sort?

    - by dvanaria
    If I have a list of elements I would like to sort, Java offers two ways to go about this. For example, lets say I have a list of Movie objects and I’d like to sort them by title. One way I could do this is by calling the one-argument version of the static java.util.Collections.sort( ) method with my movie list as the single argument. So I would call Collections.sort(myMovieList). In order for this to work, the Movie class would have to be declared to implement the java.lang.Comparable interface, and the required method compareTo( ) would have to be implemented inside this class. Another way to sort is by calling the two-argument version of the static java.util.Collections.sort( ) method with the movie list and a java.util.Comparator object as it’s arguments. I would call Collections.sort(myMovieList, titleComparator). In this case, the Movie class wouldn’t implement the Comparable interface. Instead, inside the main class that builds and maintains the movie list itself, I would create an inner class that implements the java.util.Comparator interface, and implement the one required method compare( ). Then I'd create an instance of this class and call the two-argument version of sort( ). The benefit of this second method is you can create an unlimited number of these inner class Comparators, so you can sort a list of objects in different ways. In the example above, you could have another Comparator to sort by the year a movie was made, for example. My question is, why bother to learn both ways to sort in Java, when the two-argument version of Collections.sort( ) does everything the first one-argument version does, but with the added benefit of being able to sort the list’s elements based on several different criteria? It would be one less thing to have to keep in your mind while coding. You’d have one basic mechanism of sorting lists in Java to know.

    Read the article

  • Looking for a better way to integrate a static list into a set of classes

    - by EvilTeach
    I'm trying to expand my sons interest from Warcraft 3 programming into C++ to broaden his horizons to a degree. We are planning on porting a little game that he wrote. The context goes something like this. There are Ships and Missiles, for which Ships will use Missiles and interact with them A Container exists which will hold 'a list' of ships. A Container exists which will hold 'a list' of planets. One can apply a function over all elements in the Container (for_each) Ships and Missles can be created/destroyed at any time New objects automatically insert themselves into the proper container. I cobbled a small example together to do that job, so we can talk about topics (list, templates etc) but I am not pleased with the results. #include <iostream> #include <list> using namespace std; /* Base class to hold static list in common with various object groups */ template<class T> class ObjectManager { public : ObjectManager ( void ) { cout << "Construct ObjectManager at " << this << endl; objectList.push_back(this); } virtual ~ObjectManager ( void ) { cout << "Destroy ObjectManager at " << this << endl; } void for_each ( void (*function)(T *) ) { for (objectListIter = objectList.begin(); objectListIter != objectList.end(); ++objectListIter) { (*function)((T *) *objectListIter); } } list<ObjectManager<T> *>::iterator objectListIter; static list<ObjectManager<T> *> objectList; }; /* initializer for static list */ template<class T> list<ObjectManager<T> *> ObjectManager<T>::objectList; /* A simple ship for testing */ class Ship : public ObjectManager<Ship> { public : Ship ( void ) : ObjectManager<Ship>() { cout << "Construct Ship at " << this << endl; } ~Ship ( void ) { cout << "Destroy Ship at " << this << endl; } friend ostream &operator<< ( ostream &out, const Ship &that ) { out << "I am a ship"; return out; } }; /* A simple missile for testing */ class Missile : public ObjectManager<Missile> { public : Missile ( void ) : ObjectManager<Missile>() { cout << "Construct Missile at " << this << endl; } ~Missile ( void ) { cout << "Destroy Missile at " << this << endl; } friend ostream &operator<< ( ostream &out, const Missile &that ) { out << "I am a missile"; return out; } }; /* A function suitable for the for_each function */ template <class T> void show ( T *it ) { cout << "Show: " << *it << " at " << it << endl; } int main ( void ) { /* Create dummy planets for testing */ Missile p1; Missile p2; /* Demonstrate Iterator */ p1.for_each(show); /* Create dummy ships for testing */ Ship s1; Ship s2; Ship s3; /* Demonstrate Iterator */ s1.for_each(show); return 0; } Specifically, The list is effectively embedded in each ship though the inheritance mechanism. One must have a ship, in order to access the list of ships. One must have a missile in order to be able to access the list of missiles. That feels awkward. My question boils down to "Is there a better way to do this?" Automatic object container creation Automatic object insertion Container access without requiring an object in the list to access it. I am looking for better ideas. All helpful entries get an upvote. Thanks Evil.

    Read the article

  • Using an IBAction method when it is not called from an action?

    - by cannyboy
    Are there any issues when using IBAction when it is not actually called from a user's action? If you have an action like -(IBAction)sayHello:(id)sender; You can call it from within your class like: [self sayHello:@"x"] The @"x" doesn't do anything, it just fills in for the sender. You can actually create an IBAction method without (id)sender -(IBAction)sayHello; and call it from both user's actions and from within the code, but then you won't get any useful sender info from the interface. What's the 'correct' way of filling in for the sender, when calling from the code? And can you create sender info to send when it's called from within the code? Just trying to figure it out.

    Read the article

  • Call a macro every time any method is called - Objective C

    - by Jacob Relkin
    Hi, I wrote a debug macro that prints to the console the passed-in string whenever the global kDebug flag == YES. I need to print out the name of a method and it's classname whenever any method is called. That works fine when i painstakingly go through every method and write the name of the class and the method in a string. Is there any special handler that gets called when any method in Objective-C is called, and if so, is there a way i can somehow override it to call my debug macro?? The entire purpose of this is so that I don't have to go through every method in my code and hand-code the method signature in the debug macro call. Thanks

    Read the article

  • JS: capture a static snapshot of an object at a point in time with a method

    - by Barney
    I have a JS object I use to store DOM info for easy reference in an elaborate GUI. It starts like this: var dom = { m:{ old:{}, page:{x:0,y:0}, view:{x:0,y:0}, update:function(){ this.old = this; this.page.x = $(window).width(); this.page.y = $(window).height(); this.view.x = $(document).width(); this.view.y = window.innerHeight || $(window).height(); } I call the function on window resize: $(window).resize(function(){dom.m.update()}); The problem is with dom.m.old. I would have thought that by calling it in the dom.m.update() method before the new values for the other properties are assigned, at any point in time dom.m.old would contain a snapshot of the dom.m object as of the last update – but instead, it's always identical to dom.m. I've just got a pointless recursion method. Why isn't this working? How can I get a static snapshot of the object that won't update without being specifically told to? Comments explaining how I shouldn't even want to be doing anything remotely like this in the first place are very welcome :)

    Read the article

  • How to import a class from default package

    - by mykhaylo
    Hi, I am using Eclipse 3.5 and I have created a project with some package structure along with the default package. I have one class in default package - Calculations.java and I want to make the use of that class in any of the package (for instance in com.company.calc). When I try to make the use of the class which is default package, its giving me compile error. Its not able to recognise the class in default package. Where is a problem? Calculations.java - source code public class Calculations{ native public int Calculate(int contextId); native public double GetProgress(int contextId); static { System.loadLibrary("Calc"); } } I can put my class in any other package. This class has some native method which is implemented in Delphi . If I put that class in any of the folder,I will have to make the change that DLL which I want to avoid(really - I can not). Thats why I put my class in the default package.

    Read the article

  • string extension method - Not available through WebMethod

    - by Peter Bridger
    I've written a simple extension method for a web project, it sits in a class file called StringExtensions.cs which contains the following code: using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Useful extensions for string /// </summary> static class StringExtensions { /// <summary> /// Is string empty /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsEmpty(this string value) { return value.Trim().Length == 0; } } I can access this extension method from all the classes I have within the App_Code directory. However I have a web page called JSON.aspx that contains a series of [WebMethods] - within these I cannot see the extension method - I must be missing something very obvious!

    Read the article

  • Write to static field - is FindBugs wrong in this case?

    - by htorque
    I have a Java class like this: public class Foo { public static int counter = 0; public void bar(int counter) { Foo.counter = counter; } } FindBugs warns me about writing to the static field counter via the instance method bar. However, if I change the code to: public class Foo { public static int counter = 0; public static void setCounter(int counter) { Foo.counter = counter; } public void bar(int counter) { setCounter(counter); } } Then FindBugs won't complain. Isn't that wrong? I'm still writing to a static field from an instance method, just via a static method - no?

    Read the article

  • Returning IEnumerable<T> vs IQueryable<T>

    - by stackoverflowuser
    what is the difference between returning iqueryable vs ienumerable. IQueryable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; IEnumerable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; Will both be deferred execution? When should one be preferred over the other?

    Read the article

  • RenderAction in an HtmlHelperExtension Method?

    - by TimLeung
    I am trying to call the RenderAction Extension Method within my own Html Helper: System.Web.Mvc.Html.ChildActionExtensions.RenderAction(helper, "account", "login"); this is so that along with some additional logic, I would like all html helpers to use a common method name structure when calling it on the view: <%= Html.CompanyName().RenderAccount() %> but the problem I am having is that, asp.net will complain about not finding the actual route it needs to process. It does not take in the parameters of "controller" to be used as the action and "login" to be used as the action. It seems to only reference the current route. Any ideas how I can package up the RenderAction?

    Read the article

  • When is it better to use a method versus a property for a class definition?

    - by ccomet
    Partially related to an earlier question of mine, I have a system in which I have to store complex data as a string. Instead of parsing these strings as all kinds of separate objects, I just created one class that contains all of those objects, and it has some parser logic that will encode all properties into strings, or decode a string to get those objects. That's all fine and good. This question is not about the parser itself, but about where I should house the logic for the parser. Is it a better choice to put it as a property, or as a method? In the case of a property, say public string DataAsString, the get accessor would house the logic to encode all of the data into a string, while the set accessor would decode the input value and set all of the data in the class instance. It seems convenient because the input/output is indeed a string. In the case of a method, one method would be Encode(), which returns the encoded string. Then, either the constructor itself would house the logic for the decoding a string and require the string argument, or I write a Decode(string str) method which is called separately. In either case, it would be using a method instead of a property. So, is there a functional difference between these paths, in terms of the actual running of the code? Or are they basically equivalent and it then boils down to a choice of personal preference or which one looks better? And in that kind of question... which would look cleaner anyway?

    Read the article

  • Fast ArgumentNullException with attributes. It is possible?

    - by Fraga
    Hi. Is there any fast way to verify null arguments via attributes or something? Convert this: public void Method(type arg1,type arg2,type arg3) { if (arg1== null) throw new ArgumentNullException("arg1"); if (arg2== null) throw new ArgumentNullException("arg2"); if (arg3== null) throw new ArgumentNullException("arg3"); //Business Logic } Into something like this: [VerifyNullArgument("arg1","arg2","arg3")] public void Method(type arg1,type arg2,type arg3) { //Business Logic } Ideas? thanks guys.

    Read the article

  • Good working habits to observe in project development?

    - by Will Marcouiller
    As my development experience grows, I see fit to stick to best practices from here and there to build somehow my own working practices while observing the conventions, etc. I'm currently working on a project which my goals is to graduate the security access model from an environment's Active Directory to another environment's automatically. I don't know for any of you, but as far as I'm concerned, I meet some real difficulties sticking to only one way, then develop. I mean, I learn something new everyday while visiting SO, and recently wanted to get acquainted with generics. On the other hand, I better know the Façade pattern which proved to be very practical in transactional programming in process systems. This seems to be less practical for desktop application as there are plenty of variables to consider in a desktop application that you don't have to care in transactional programming, as you're playing only with information data. As for my current project, I have: Groups; Organizational Units; Users. Which are all considered an entry in the Active Directory. This points out to be a good candidate for generics, as also approached this way by Bart de Smett's Linq to AD on CodePlex. He has a DirectorySource<T>, and to manage let's say groups, then he instantiate a source with the proper type: var groups = new DirectorySource<Group>(); This seems to be very a good way of doing. Despite, I seem to go from one pattern to another and I don't seem to be able to strictly stick to one. While I'm aware that one must not stay with only one way of doing, since each pattern statisfies certain advantages, while also illustrating disadvantages under some usage conditions, I seem to want to develop with both patterns having a singleton Façade class with the underlying factories which represent the sub systems: GroupsFactory; UsersFactory; OrganizationalUnitsFactory. Each of the factories offers the possible operations for their respective entity (group, user, OU). To make a very long story short, I often have plenty of ideas while developping and this causes me some trouble, as I go from an idea to another feeling completely lost after a while. Yet I understand the advantages and disavantages, I have no trouble choosing from one pattern to another depending on the situation. Nevertheless, when it comes to programming itself, if I'm not part of a team, I feel sometimes like I can't do anything good. That is, because I can't stand not doing something "perfect" the first time. The role I play within the project is both: the project manager and the programmer. I am more comfortable in the project manager role, architectural role, analytical role than the developer's. Has any of you some good habbits to observe in project development? Thanks to you all! =)

    Read the article

  • Lisp, OCaml or what for Runge Kutta?

    - by Eelvex
    Which language would you propose for solving a system with: first order differential equations complex variables N-dimensions using 4th order Runge Kutta or the like. Speed matters a lot but would sacrifice for: Elegant (clean and short) code Flexibility + scalability I'm mostly between a Lisp and OCaml but any other suggestion is welcomed. Thanks!

    Read the article

  • Rails NoMethodError in loop when method exists

    - by Kevin Whitaker
    Good day all. I'm running into a bit of a problem getting a script running on my production environment, even though it works just fine on my dev box. I've verified that all the requisite gems and such are the same version. I should mention that the script is intended to be run with the script/runner command. Here is a super-condensed version of what I'm trying to do, centered around the part that's broken: def currentDeal marketTime = self.convertToTimeZone(Time.new) deal = Deal.find(:first, :conditions = ["start_time ? AND market_id = ? AND published = ?", marketTime, marketTime, self.id, 1]) return deal end markets = Market.find(all) markets.each do |market| deal = market.currentDeal puts deal.subject end Now convertToTimeZone is a method attached to the model. So, this code works just fine on my dev machine, as stated. However, attempting to run it on my production machine results in: undefined method `subject' for nil:NilClass (NoMethodError) If, however, I go into the console on the production box and do this: def currentDeal marketTime = self.convertToTimeZone(Time.new) deal = Deal.find(:first, :conditions = ["start_time ? AND market_id = ? AND published = ?", marketTime, marketTime, self.id, 1]) return deal end market = Market.find(1) deal = market.currentDeal puts deal.subject It returns the correct value, no problem. So what is going on? This is on rails v 2.3.5, on both machines. Thanks for any help

    Read the article

  • Does Java support default parameter values?

    - by gnavi
    I came across some Java code that had the following structure: public MyParameterizedFunction(String param1, int param2) { this(param1, param2, false); } public MyParameterizedFunction(String param1, int param2, boolean param3) { //use all three parameters here } I know that in C++ I can assign a parameter a default value. For example: void MyParameterizedFunction(String param1, int param2, bool param3=false); Does Java support this kind of syntax? Are there any reasons why this two step syntax is preferable?

    Read the article

  • In an extension method how do a create an object based on the implementation class

    - by Greg
    Hi, In an extension method how do a create an object based on the implementation class. So in the code below I wanted to add an "AddRelationship" extension method, however I'm not sure how within the extension method I can create an Relationship object? i.e. don't want to tie the extension method to this particular implementation of relationship public static class TopologyExtns { public static void AddNode<T>(this ITopology<T> topIf, INode<T> node) { topIf.Nodes.Add(node.Key, node); } public static INode<T> FindNode<T>(this ITopology<T> topIf, T searchKey) { return topIf.Nodes[searchKey]; } public static bool AddRelationship<T>(this ITopology<T> topIf, INode<T> parentNode, INode<T> childNode) { var rel = new RelationshipImp(); // ** How do I create an object from teh implementation // Add nodes to Relationship // Add relationships to Nodes } } public interface ITopology<T> { //List<INode> Nodes { get; set; } Dictionary<T, INode<T> > Nodes { get; set; } } public interface INode<T> { // Properties List<IRelationship<T>> Relationships { get; set; } T Key { get; } } public interface IRelationship<T> { // Parameters INode<T> Parent { get; set; } INode<T> Child { get; set; } } namespace TopologyLibrary_Client { class RelationshipsImp : IRelationship<string> { public INode<string> Parent { get; set; } public INode<string> Child { get; set; } } } public class TopologyImp<T> : ITopology<T> { public Dictionary<T, INode<T>> Nodes { get; set; } public TopologyImp() { Nodes = new Dictionary<T, INode<T>>(); } } thanks

    Read the article

  • Fatal error: Function name must be a string in.. PHP error

    - by Jonesy
    Hi I have a class called User and a method called insertUser(). function insertUser($first_name, $last_name, $user_name, $password, $email_address, $group_house_id) { $first_name = mysql_real_escape_string($first_name); $last_name = mysql_real_escape_string($last_name); $user_name = mysql_real_escape_string($user_name); $password = mysql_real_escape_string($password); $email_address = mysql_real_escape_string($email_address); $query = "INSERT INTO Users (FirstName,LastName,UserName,Password,EmailAddress, GroupHouseID) VALUES ('$first_name','$last_name','$user_name','$password','$email_address','$group_house_id')"; $mysql_query($query); } And I call it like this: $newUser = new User(); $newUser->insertUser($first_name, $last_name, $user_name, $email, $password, $group_house_id); When I run the code I get this error: Fatal error: Function name must be a string in /Library/WebServer/Documents/ORIOnline/includes/class_lib.php on line 33 Anyone know what I am doing wronly? Also, this is my first attempt at OO PHP. Cheers, Jonesy

    Read the article

  • Runge-Kutta Method with adaptive step

    - by infoholic_anonymous
    I am implementing Runge-Kutta method with adaptive step in matlab. I get different results as compared to matlab's own ode45 and my own implementation of Runge-Kutta method with fixed step. What am I doing wrong in my code? Is it possible? function [ result ] = rk4_modh( f, int, init, h, h_min ) % % f - function handle % int - interval - pair (x_min, x_max) % init - initial conditions - pair (y1(0),y2(0)) % h_min - lower limit for h (step length) % h - initial step length % x - independent variable ( for example time ) % y - dependent variable - vertical vector - in our case ( y1, y2 ) function [ k1, k2, k3, k4, ka, y ] = iteration( f, h, x, y ) % core functionality performed within loop k1 = h * f(x,y); k2 = h * f(x+h/2, y+k1/2); k3 = h * f(x+h/2, y+k2/2); k4 = h * f(x+h, y+k3); ka = (k1 + 2*k2 + 2*k3 + k4)/6; y = y + ka; end % constants % relative error eW = 1e-10; % absolute error eB = 1e-10; s = 0.9; b = 5; % initialization i = 1; x = int(1); y = init; while true hy = y; hx = x; %algorithm [ k1, k2, k3, k4, ka, y ] = iteration( f, h, x, y ); % error estimation for j=1:2 [ hk1, hk2, hk3, hk4, hka, hy ] = iteration( f, h/2, hx, hy ); hx = hx + h/2; end err(:,i) = abs(hy - y); % step adjustment e = abs( hy ) * eW + eB; a = min( e ./ err(:,i) )^(0.2); mul = a * s; if mul >= 1 % step length admitted keepH(i) = h; k(:,:,i) = [ k1, k2, k3, k4, ka ]; previous(i,:) = [ x+h, y' ]; %' i = i + 1; if floor( x + h + eB ) == int(2) break; else h = min( [mul*h, b*h, int(2)-x] ); x = x + keepH(i-1); end else % step length requires further adjustments h = mul * h; if ( h < h_min ) error('Computation with given precision impossible'); end end end result = struct( 'val', previous, 'k', k, 'err', err, 'h', keepH ); end The function in question is: function [ res ] = fun( x, y ) % res(1) = y(2) + y(1) * ( 0.9 - y(1)^2 - y(2)^2 ); res(2) = -y(1) + y(2) * ( 0.9 - y(1)^2 - y(2)^2 ); res = res'; %' end The call is: res = rk4( @fun, [0,20], [0.001; 0.001], 0.008 ); The resulting plot for x1 : The result of ode45( @fun, [0, 20], [0.001, 0.001] ) is:

    Read the article

< Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >