// using Rails 2.3.5
//routes.rb
map.resources :users,
>> user = User.first
>> helper.link_to user.name, user
I am getting nil error. I thought the above code should work. What am I missing?
I Use the following code to load png image:
UIImage *imageBack1 = [UIImage imageNamed:@"Bar1.png"];
UIImage *imageBack2 = [UIImage imageNamed:@"Bar2.png"];
imageBack1 work right when imageBack2's value is nil,
Bar1.png and Bar2.png are located at the same place,but why Bar2.png couldn't be load?
I try to make a UIImageView open like a hatch, and under the "hatchView" its anoter imageView
but when I start the animation its like the view under gets over and cover the animation,
When the animation gets over the imageView the its getting visibel.
its works fine if a remove the imageView thats under.
Here is the code for animation view.
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *) event {
if (!isHatchOpen) {
if (hatchView.layer.anchorPoint.x != 0.0f) {
hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y);
}
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:hatchView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
float pct = location.x / 320.0f;
float rad = acosf(pct);
CATransform3D transform = CATransform3DMakeRotation(-rad+5, 0.0f, -1.0f, 0.0f);
transform.m14 = (1.0 / -2000) * acosf(pct);
hatchView.layer.transform = transform;
[UIView commitAnimations];
isHatchOpen = YES;
} else {
if (hatchView.layer.anchorPoint.x != 0.0f) {
hatchView.layer.anchorPoint = CGPointMake(0.0f, 0.5f);
hatchView.center = CGPointMake(hatchView.center.x - hatchView.bounds.size.width/2.0f, hatchView.center.y);
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationBeginsFromCurrentState:YES];
CATransform3D transform = CATransform3DMakeRotation(0, 0.0f, -1.0f, 0.0f);
transform.m14 = 0;
hatchView.layer.transform = transform;
// Commit the changes
[UIView commitAnimations];
isHatchOpen = NO;
}
}
And here a add the Views
hatchView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, frame.size.width-1, frame.size.height-2)];
[self addSubview:hatchView];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, frame.size.width-2, frame.size.height-2)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self insertSubview:imageView belowSubview:hatchView];
I manage to pass the following array from MessagesTableViewController.m to arraySelectedCategory in another class called MessageDetailViewController.m:
self.messageDetailViewController.arraySelectedCategory =
[[NSMutableArray alloc] initWithObjects:@"Value 1",@"Value 2", @"Value 3", nil];
but how do I hand over an array stored in: NSMutableArray *categories;
self.messageDetailViewController.arraySelectedCategory = ?????
Thanks!
I've done some reorganizing of my project recently and now I'm not seeing my tab bar controller, but its first view controller's view is appearing. Here's a breakdown of everything that happens prior to the problem.
App Delegate loads FirstViewController with nib. FirstViewController loads the application data from my server and then presents MainViewController with a modal transition. MainViewController is where the UITabBarController is supposed to be appearing. It's a very simple class.
The .h
@interface MainViewController : UIViewController <UITabBarControllerDelegate> {
IBOutlet UITabBarController *tabBarController;
}
@property (nonatomic, retain) UITabBarController *tabBarController;
@end
The .m
@implementation MainViewController
@synthesize tabBarController;
- (void)viewDidLoad {
NSLog(@"MainViewController viewDidLoad");
//set tab bar controller delegate to self
tabBarController.delegate = self;
// home view
HomeViewController *home = [[HomeViewController alloc] initWithTab];
// menu view
MenuViewController *menu = [[MenuViewController alloc] initWithTab];
// special offers view
SpecialOffersViewController *so = [[SpecialOffersViewController alloc] initWithTab];
// events view
EventsViewController *events = [[EventsViewController alloc] initWithTab];
// info view
InfoViewController *info = [[InfoViewController alloc] initWithTab];
//populate the tab bar controller with view controllers
NSArray *controllers = [NSArray arrayWithObjects:home, menu, so, events, info, nil];
tabBarController.viewControllers = controllers;
//release view controllers
[home release];
[menu release];
[so release];
[events release];
[info release];
[controllers release];
//add tab bar controller to view
[self.view addSubview:tabBarController.view];
[super viewDidLoad];
}
and here's the bit from FirstViewController that modally presents the MainViewController...
MainViewController *controller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
I'm not getting any compiler errors or warnings and the app runs swell... no crashing. It just isn't showing the darned TabBar, and it used to when I was creating it on my AppDelegate. I checked everything in my NIB and my outlets seem to be hooked up ok. I have no idea what's happened. Help!
If my iPad is in Landscape mode and presentModalViewController is called the view automatically turns into portrait mode. Any solutions?
UIViewController * start = [[UIViewController alloc]initWithNibName:@"SecondView" bundle:nil];
start.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
start.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:start animated:YES];
In SecondView I've already added:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Hello,
I often need to assign a variable, if the source value is set. So far I have done it like this:
filters[:red] = params[:search][:red] unless params[:search][:red].nil?
This works but looks a bit clumsy. There must be a more DRY way of getting this result.
Any suggestions?
Best regards.
Asbjørn Morell.
So I know in ruby that x.nil? will test if x is null.
What is the simplest way to test if x equals ' ', or ' ', or ' ', etc?
Basically, I'm wondering what the best way to test if a variable is all whitespace?
I am new in iphone i am developing a application that take value from data base and display data in tableview. in this application we save data from one data table to other data table this is when add first time work and when we do second time application is crash. how to solve this problem i am not understand code is given bellow
my appdelegate code for insert value from one table to other is given bellow
-(void)sopinglist
{
//////databaseName= @"SanjeevKapoor.sqlite";
databaseName =@"AjeetTest.sqlite";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath =[documentsDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
list1 = [[NSMutableArray alloc] init];
sqlite3 *database;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
if(addStmt == nil) {
///////////const char *sql = "insert into Dataa(item) Values(?)";
const char *sql = " insert into Slist select * from alootikki";
///////////// const char *sql =" Update Slist ( Incredients, Recipename,foodtype) Values(?,?,?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
/////for( NSString * j in k)
sqlite3_bind_text(addStmt, 1, [k UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_int(addStmt,1,i); // sqlite3_bind_text(addStmt, 1, [coffeeName UTF8String], -1, SQLITE_TRANSIENT);
// sqlite3_bind_double(addStmt, 2, [price doubleValue]);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
coffeeID = sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
// sqlite3_clear_bindings(detailStmt);
//}
}
sqlite3_finalize(addStmt);
addStmt = nil;
sqlite3_close(database);
}
And the table View code for access data from database is given bellow
SanjeevKapoorAppDelegate *appDelegate =(SanjeevKapoorAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate sopinglist];
////[appDelegate recpies];
/// NSArray *a =[[appDelegate list1] componentsJoinedByString:@","];
k= [[appDelegate list1] componentsJoinedByString:@","];
I have something like
- (void)getData:(SomeParameter*)param
{
// Remotely call out for data returned asynchronously
// returns data via a delegate method
}
- (void)handleDataDelegateMethod:(NSData*)data
{
// Handle returned data
}
I want to write a unit test for this, how can I do something better than
NSData* returnedData = nil;
- (void)handleDataDelegateMethod:(NSData*)data
{
returnedData = data;
}
- (void)test
{
[obj getData:param];
while (!returnedData)
{
[NSThread sleep:1];
}
// Make tests on returnedData
}
This is quite a quick question. I currently use
do_this if (testvar ||= false)
Which works just fine.
But this approach unnerves me because while fast, it does not short-circuit like defined?(testvar) && testvar does, and it instantiates and assigns a value to a local variable that is subsequently never used, which seems inefficient.
I enjoy the very reasonable fact that instance variables are nil before assignment, but I'd like for the situation to be just as easy for local variables.
I have a simple model named Foo.
Foo has two columns, bar and foobar.
Doing a simple Foo.find_by_bar("a") is returning nil. There is a record in the table where bar contains a. Also, what's even more troubling, is I don't see the query even happening in the development log.
A simple Foo.find(1) works though.
I don't even know the proper terminology for this lisp syntax, so I don't know if the words I'm using to ask the question, make sense. But the question makes sense, I'm sure.
So let me just show you. cc-mode (cc-fonts.el) has things called "matchers" which are bits of code that run to decide how to fontify a region of code. That sounds simple enough, but the matcher code is in a form I don't completely understand, with babckticks and comma-atsign and just comma and so on, and furthermore it is embedded in a c-lang-defcost, which itself is a macro. And I want to run edebug on that code.
Look:
(c-lang-defconst c-basic-matchers-after
"Font lock matchers for various things that should be fontified after
generic casts and declarations are fontified. Used on level 2 and
higher."
t `(;; Fontify the identifiers inside enum lists. (The enum type
;; name is handled by `c-simple-decl-matchers' or
;; `c-complex-decl-matchers' below.
,@(when (c-lang-const c-brace-id-list-kwds)
`((,(c-make-font-lock-search-function
(concat
"\\<\\("
(c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds))
"\\)\\>"
;; Disallow various common punctuation chars that can't come
;; before the '{' of the enum list, to avoid searching too far.
"[^\]\[{}();,/#=]*"
"{")
'((c-font-lock-declarators limit t nil)
(save-match-data
(goto-char (match-end 0))
(c-put-char-property (1- (point)) 'c-type
'c-decl-id-start)
(c-forward-syntactic-ws))
(goto-char (match-end 0)))))))
I am reading up on lisp syntax to figure out what those things are and what to call them, but aside from that, how can I run edebug on the code that follows the comment that reads ;; Fontify the identifiers inside enum lists. ?
I know how to run edebug on a defun - just invoke edebug-defun within the function's definition, and off I go. Is there a corresponding thing I need to do to edebug the cc-mode matcher code forms?
I found email composer sample code from iphone OS Ref Library. Here is a code-
Code:
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
My question is how to take user's input? Here all email address are predefined in code. so what are the IDs of to, CC, Bcc, subject and body fields?
I'm attempting to create an NSArray with a grouping of string literals, however I get the compile error "Initializer element is not constant".
NSArray *currencies = [NSArray arrayWithObjects:@"Dollar", @"Euro", @"Pound", nil];
Could someone point out what I'm doing wrong, and possibly explain the error message?
UISomeController *controller = [[UISomeController alloc] initWithNibName:@"UISomeController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
Is it possible to initialize some variables in the controller at the creation time? And how to do that?
Still working on lisp recipes and idioms.
I have a list like this:
((a b c) (d e f) nil (g h))
I'd like to consolidate that to one list,
(a b c d e f g h)
Seems like there oughta be a one-liner for that.
When a user gets to this screen, there is no way to cancel out of it. What can I do?
To get this view in the first place I am running:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
vid, @"link",
vid, @"source",
vid, @"picture",
@"My Place", @"name",
@"YouTube Presentation", @"caption",
title, @"description",
@"Enjoy this Video", @"message",
nil];
[app.facebook dialog:@"stream.publish"
andParams:params
andDelegate:self];
If you put the aif code presented in onlisp in a package and try to use it in another you run in the problem that packagename:it is not external.
(in-package :packagename)
(defmacro aif (test-form then-form &optional else-form)
‘(let ((it ,test-form))
(if it ,then-form ,else-form)))
wanted call syntax
(in-package :otherpackage)
(aif (do-stuff)
(FORMAT t "~a~%" it)
(FORMAT t "just got nil~%"))
How can I fix this behavior in code, without making the variable it external in the package declaration and beeing able to access it just by it instead of packagename:it?
Consider the following situation:
We have two Localizable.string files, one in en.lproj and one in it.lproj
When the user switches to English or Italian, the proper localized string is loaded using NSLocalizedString(@"keyword", nil)
If one of the files is missing the keyword, the string is not retrieved
Is there any way to make this macro load the string from a specific language if it's keyword is not found in the current locale's Localizable.string?
Hi all,
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might be able to help me out with this. I'm fairly new to Obj-C and XCode, and I'm faced with this really... weird... problem. Googling hasn't turned up anything whatsoever. Basically, I get an EXC_BAD_ACCESS signal on a line that doesn't do any dereferencing or anything like that that I can see. Wondering if you guys have any idea where to look for this. I've found a work around, but no idea why this works... The line the broken version barfs out on is the line:
LevelEntity *le = entity;
where I get my bad access signal.
Here goes:
THIS VERSION WORKS
NSArray *contacts = [self.body getContacts];
for (PhysicsContact *contact in contacts)
{
PhysicsBody *otherBody;
if (contact.bodyA == self.body)
{
otherBody = contact.bodyB;
}
if (contact.bodyB == self.body)
{
otherBody = contact.bodyA;
}
id entity = [otherBody userData];
if (entity != nil)
{
LevelEntity *le = entity;
CGPoint point = [contact contactPointOnBody:otherBody];
}
}
THIS VERSION DOESNT WORK
NSArray *contacts = [self.body getContacts];
for (NSUInteger i = 0; i < [contacts count]; i++)
{
PhysicsContact *contact = [contacts objectAtIndex:i];
PhysicsBody *otherBody;
if (contact.bodyA == self.body)
{
otherBody = contact.bodyB;
}
if (contact.bodyB == self.body)
{
otherBody = contact.bodyA;
}
id entity = [otherBody userData];
if (entity != nil)
{
LevelEntity *le = entity;
CGPoint point = [contact contactPointOnBody:otherBody];
}
}
Here, the only difference between the two examples is the way I enumerate through my array. In the first version (which works) I use for (... in ...), where as in the second I use for (...; ...; ...). As far as I can see, these should be the same.
This is seriously weirding me out. Anyone have any similar experience or idea whats going on here? Would be really great :)
Cheers,
Alex
I've started getting the following error in one of my views for some reason, I don't get it in development, but only in production.
Here is a snippet of the backtrace, any ideas?
ActionView::Template::Error (code converter not found (UTF-8 to UTF-16)):
19: [title, summary.gsub(/^/, " "), nil].join("\n\n")
20: end
21: end.join
22: sections = sections.force_encoding('UTF-8').encode('UTF-16', :invalid => :replace).encode('UTF-8') if sections.respond_to?(:force_encoding)
23: %>
24:
25: <%= raw sections %>
How would you add a delay between certain method being called?
This is my code that I want to only trigger 30 times per second:
- (void) scrollViewDidScroll: (UIScrollView*)scrollView {
[self performSelector:@selector(needsDisplay) withObject:nil afterDelay:0.033];
}
- (void) needsDisplay {
[captureView setNeedsDisplay];
}
If I leave it like this, it only gets called after the user stopped scrolling.
What I want to do is call the method when the user is scrolling, but with a delay of 33 milliseconds between each call.
I found out this morning that proc.new works in a class initialize method, but not lambda. Concretely, I mean:
class TestClass
attr_reader :proc, :lambda
def initialize
@proc = Proc.new {puts "Hello from Proc"}
@lambda = lambda {puts "Hello from lambda"}
end
end
c = TestClass.new
c.proc.call
c.lambda.call
In the above case, the result will be:
Hello from Proc
test.rb:14:in `<main>': undefined method `call' for nil:NilClass (NoMethodError)
Why is that?
Thanks!