Search Results

Search found 5 results on 1 pages for 'customclasses'.

Page 1/1 | 1 

  • Unable to access a primitive array inside a custom class from a UIViewController instance

    - by Daniel
    Hello! I have made a subclass of NSObject that is meant to be the model of my application. The class has a few methods and on instance primitive array as such: @interface Cube : NSObject { int cubeState[5][2][2]; } - (id)printContent; @end @implementation Cube - (void)init { if (self = [super init]) { for (int i=0; i<=5; i++) { for (int j=0; j<=2; j++) { for (int k=0; k<=2; k++) { cubeState[i][j][k] = i; } } } } return self; } - (void)printContent { for (int i=0; i<=5; i++) { for (int j=0; j<=2; j++) { for (int k=0; k<=2; k++) { NSLog(@"[%d] [%d] [%d] = %d", i, j, k, cubeState[i][j][k]); } } } } @end This works fine if instanciated from the delegate as such: #include "Cube.h" @implementation CubeAppDelegate @synthesize window; - (void)applicationDidFinishLaunching:(UIApplication *)application { Cube *cube = [[Cube alloc] init]; [cube printContent]; [cube release]; [window makeKeyAndVisible]; } However, the application crashes if I try to create a subclass of UIViewController with a Cube *cube property and later try to access the Cube instance object through the view controller's property as such: @interface CustomController : UIViewController { Cube *cube; } @property (nonatomic, retain) Cube *cube; @end @implementation CustomController @synthesize cube; - (void)dealloc { [cube release]; [super dealloc]; } @end and in the delegate: - (void)applicationDidFinishLaunching:(UIApplication *)application { viewController = [[CustomController alloc] initWithNibName:@"MainView" bundle:nil]; viewController.cube = [[[Cube alloc] init] autorelease]; [viewController.cube printContent]; // Application crashes here } Any ideas?

    Read the article

  • Why I cannot get correct class of a custom class through isKindOfClass?

    - by Anthony Chan
    Hi, I've created a custom class AnimalView which is a subclass of UIView containing a UILabel and a UIImageView. @interface AnimalView : UIView { UILabel *nameLabel; UIImageView *picture; } Then I added in several AnimalView onto the ViewController.view. In the touchesBegan:withEvent: method, I wanted to detect if the touched object is an AnimalView or not. Here is the code for the viewController: @implementation AppViewController - (void)viewDidLoad { UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:... [self.view addSubview scrollview]; for (int i = 0; i<10; i++) { AnimalView *newAnimal = [[AnimalView alloc] init]; // customization of newAnimal [scrollview addSubview:newAnimal; } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *hitView = touch.view; if ([hitView isKindOfClass:[AnimalView class]]) { AnimalView *animal = (AnimalView *)hitView; [animal doSomething]; } } However, nothing happened when I clicked on the animal. When I checked the class of hitView by NSLog(@"%@", [hitView class]), it always shows UIView instead of AnimalView. Is it true that the AnimalView changed to a UIView when it is added onto the ViewController? Is there any way I can get back the original class of a custom class?

    Read the article

  • Custom array class with assotiated objects

    - by FancyDancy
    I have a simple structure, it's just an array of model's objects. For example, it's a users with books. @books = Book.find(:all, :include = :users) I need to check, does user have a book? I have written a helper method: def has_book?(user_id) @books.select{|b| b.user_id == user_id}.any? end Then, i need to get only books from selected library def in_library(n) @books.select{|b| b.library == n} end I have tried to make custom Array class: class BooksList < Array def initialize(books) self << books end # its my custom methods def has_book?(user_id) self.select{|b| b.user_id == user_id}.any? end def in_library(n) self.select{|b| b.library == n} end end It works, but i have only one problem. I can't access Book's assotiated object (user). So i can't write: @books = BookList.new(Book.find(:all, :include => :users)) @books.first.user.id # it says undefined method `user' for #<Array:0x104b43e08>

    Read the article

  • declare decision structure inside of a System.out.println

    - by user2899249
    So I am working on an assignment where I have to have a print method in a constructor that displays a distance. I also have to have three separate get methods depending on what the input is in the demo class. My question is that I am trying to write the print method to contain a decision structure based on which get is used. public void prt() { DecimalFormat formatter = new DecimalFormat("#,##0.00"); System.out.println("The time it takes the sound to travel " + distance + " feet through air is " + if (getSpeedInAir() > 0) { formatter.format(getSpeedInAir()); } else if (getSpeedInWater() > 0) { formatter.format(getSpeedInWater()); } else if (getSpeedInSteel() > 0) { formatter.format(getSpeedInSteel()); } else "error";) } After trying to compile I am getting the following errors. Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\GlaDOS\Desktop\JavaStuffj Speed C:\Users\GlaDOS\Desktop\JavaStuffdel *.class C:\Users\GlaDOS\Desktop\JavaStuffjavac Speed.java Speed.java:43: error: illegal start of expression " feet through air is " + if (getSpeedInAir() 0) ^ Speed.java:43: error: ';' expected " feet through air is " + if (getSpeedInAir() 0) ^ Speed.java:43: error: not a statement " feet through air is " + if (getSpeedInAir() 0) ^ Speed.java:43: error: ';' expected " feet through air is " + if (getSpeedInAir() 0) ^ Speed.java:47: error: 'else' without 'if' else if (getSpeedInWater() > 0) ^ Speed.java:56: error: not a statement "error";) ^ Speed.java:56: error: illegal start of expression "error";) ^ 7 errors C:\Users\GlaDOS\Desktop\JavaStuffjava Speed Error: Could not find or load main class Speed Any help on why this is happening would be greatly appreciated.

    Read the article

  • Dojo - How to position tooltip close to text?

    - by user244394
    Like the title says i want to be able to display the tooltip close to the text, currently it is displayed far away in the cell. Tobe noted the tooltip positions correctly for large text, only fails for small text. In DOJO How can i position the tooltip close to the text? I have this bit of code snippet that display the tooltip in the grid cells. Screenshot attached, html <div class="some_app claro"></div> ... com.c.widget.EnhancedGrid = function ( aParent, options ) { var grid, options; this.theParentApp = aParent; dojo.require("dojox.grid.EnhancedGrid"); dojo.require("dojox.grid.enhanced.plugins.Menu"); dojo.require("dojox.grid.enhanced.plugins.Selector"); dojo.require("dojox.grid.enhanced.plugins.Pagination"); dojo.require("dojo.store.Memory"); dojo.require("dojo.data.ObjectStore"); dojo.require("dojo._base.xhr"); dojo.require("dojo.domReady!"); dojo.require("dojo.date.locale"); dojo.require("dojo._base.connect"); dojo.require("dojox.data.JsonRestStore"); dojo.require("dojo.data.ItemFileReadStore"); dojo.require("dijit.Menu"); dojo.require("dijit.MenuItem"); dojo.require('dijit.MenuSeparator'); dojo.require('dijit.CheckedMenuItem'); dojo.require('dijit.Tooltip'); dojo.require('dojo/query'); dojo.require("dojox.data.QueryReadStore"); // main initialization function this.init = function( options ) { var me = this; // default options var defaultOptions = { widgetName: ' Enhancedgrid', render: true, // immediately render the grid draggable: true, // disables column dragging containerNode: false, // the Node to hold the Grid (optional) mashupUrl: false, // the URL of the mashup (required) rowsPerPage: 20, //Default number of items per page columns: false, // columns (required) width: "100%", // width of grid height: "100%", // height of grid rowClass: function (rowData) {}, onClick: function () {}, headerMenu: false, // adding a menu pop-up for the header. selectedRegionMenu: false, // adding a menu pop-up for the rows. menusObject: false, //object to start-up the menus using the plug-in. sortInfo: false, // The column default sort infiniteScrolling: false //If true, the enhanced grid will have an infinite scrolling. }; // merge user provided options me.options = jQuery.extend( {}, defaultOptions, options ); // check we have minimum required options if ( ! me.options.mashupUrl ){ throw ("You must supply a mashupUrl"); } if ( ! me.options.columns ){ throw ("You must supply columns"); } // make the column for formatting based on its data type. me.preProcessColumns(); // create the Contextual Menu me.createMenu(); // create the grid object and return me.createGrid(); }; // Loading the data to the grid. this.loadData = function () { var me = this; if (!me.options.infiniteScrolling) { var xhrArgs = { url: me.options.mashupUrl, handleAs: "json", load: function( data ){ var store = new dojo.data.ItemFileReadStore({ data : {items : eval( "data."+me.options.dataRoot)}}); store.fetch({ onComplete : function(items, request) { if (me.grid.selection !== null) { me.grid.selection.clear(); } me.grid.setStore(store); }, onError : function(error) { me.onError(error); } }); }, error: function (error) { me.onError(error); } }; dojo.xhrGet(xhrArgs); } else { dojo.declare('NotificationQueryReadStore', dojox.data.QueryReadStore, { // // hacked -- override to map to proper data structure // from mashup // _xhrFetchHandler : function(data, request, fetchHandler, errorHandler) { // // TODO: need to have error handling here when // data has "error" data structure // // // remap data object before process by super method // var dataRoot = eval ("data."+me.options.dataRoot); var dataTotal = eval ("data."+me.options.dataTotal); data = { numRows : dataTotal, items : dataRoot }; // call to super method to process mapped data and // set rowcount // for proper display this.inherited(arguments); } }); var queryStore = new NotificationQueryReadStore({ url : me.options.mashupUrl, urlPreventCache: true, requestMethod : "get", onError: function (error) { me.onError(error); } }); me.grid.setStore(queryStore); } }; this.preProcessColumns = function () { var me = this; var options = me.options; for (i=0;i<this.options.columns.length;i++) { if (this.options.columns[i].formatter==null) { switch (this.options.columns[i].datatype) { case "string": this.options.columns[i].formatter = me.formatString; break; case "date": this.options.columns[i].formatter = me.formatDate; var todayDate = new Date(); var gmtTime = c.util.Date.parseDate(todayDate.toString()).toString(); var gmtval = gmtTime.substring(gmtTime.indexOf('GMT'),(gmtTime.indexOf('(')-1)); this.options.columns[i].name = this.options.columns[i].name + " ("+gmtval+")"; } } if (this.options.columns[i].sortDefault) { me.options.sortInfo = i+1; } } }; // create GRID object using supplied options this.createGrid = function () { var me = this; var options = me.options; // create a new grid this.grid = new dojox.grid.EnhancedGrid ({ width: options.width, height: options.height, query: { id: "*" }, keepSelection: true, formatterScope: this, structure: options.columns, columnReordering: options.draggable, rowsPerPage: options.rowsPerPage, //sortInfo: options.sortInfo, plugins : { menus: options.menusObject, selector: {"row":"multi", "cell": "disabled" }, }, //Allow the user to decide if a column is sortable by setting sortable = true / false canSort: function(col) { if (options.columns[Math.abs(col)-1].sortable) return true; else return false; }, //Change the row colors depending on severity column. onStyleRow: function (row) { var grid = me.grid; var item = grid.getItem(row.index); if (item && options.rowClass(item)) { row.customClasses += " " +options.rowClass(item); if (grid.selection.selectedIndex == row.index) { row.customClasses += " dojoxGridRowSelected"; } grid.focus.styleRow(row); grid.edit.styleRow(row); } }, onCellMouseOver: function (e){ // var pos = dojo.position(this, true); // alert(pos); console.log( e.rowIndex +" cell node :"+ e.cellNode.innerHTML); // var pos = dojo.position(this, true); console.log( " pos :"+ e.pos); if (e.cellNode.innerHTML!="") { dijit.showTooltip(e.cellNode.innerHTML, e.cellNode); } }, onCellMouseOut: function (e){ dijit.hideTooltip(e.cellNode); }, onHeaderCellMouseOver: function (e){ if (e.cellNode.innerHTML!="") { dijit.showTooltip(e.cellNode.innerHTML, e.cellNode); } }, onHeaderCellMouseOut: function (e){ dijit.hideTooltip(e.cellNode); }, }); // ADDED CODE FOR TOOLTIP var gridTooltip = new Tooltip({ connectId: "grid1", selector: "td", position: ["above"], getContent: function(matchedNode){ var childNode = matchedNode.childNodes[0]; if(childNode.nodeType == 1 && childNode.className == "user") { this.position = ["after"]; this.open(childNode); return false; } if(matchedNode.className && matchedNode.className == "user") { this.position = ["after"]; } else { this.position = ["above"]; } return matchedNode.textContent; } }); ... //Construct the grid this.buildGrid = function(){ var datagrid = new com.emc.widget.EnhancedGrid(this,{ Url: "/dge/api/-resultFormat=json&id="+encodeURIComponent(idUrl), dataRoot: "Root.ATrail", height: '100%', columns: [ { name: 'Time', field: 'Time', width: '20%', datatype: 'date', sortable: true, searchable: true, hidden: false}, { name: 'Type', field: 'Type', width: '20%', datatype: 'string', sortable: true, searchable: true, hidden: false}, { name: 'User ID', field: 'UserID', width: '20%', datatype: 'string', sortable: true, searchable: true, hidden: false } ] }); this.grid = datagrid; };

    Read the article

1