use code init UITextView, Constraints not working - autolayout

use code init UITextView, Constraints retuen the NSArray count is 0
- (void)textViewDidChange:(UITextView *)textView{
NSLog(#"constraints:%#",textView.constraints);}
2016-08-08 17:43:32.347 demo[5756:2552780] constraints:()
but use storyboard init is ok.

Related

Failed to run a new application with exit code:1

please forward my following answer to node.js: Mongodb db.collection.find() not working while collection.insert works
you did use: collection.find({name:req.body.name}).limit(1).size()
1 you can also use cursor variable for limit. or different syntax from mongo shell.
2 or use the cursor var within your javascript file(see below):
------------------------------------------------
1
(mongo-shell)> db.collection.find({name:req.body.name},{$limit:1,$skip:10})
or:
db.collection.find({name:req.body.name},"$limit":1,"$skip":10})
or better use the cursor var within your js file:
var query = {name:req.body.name}
var cursor=db.collection.find(query);
cursor.sort({"name":1});`enter code here`
cursor.limit(10);
cursor.skip(100);

restubbing method in OCMock does not seem to work?

I am confused why this doesn't work...
[[[myObject stub] andReturnValue:#YES] isBadical];
NSLog(#"================> result: %i", [myObject isBadical]);
[[[myObject stub] andReturnValue:#NO] isBadical];
NSLog(#"================> new result: %i", [myObject isBadical]);
Result is:
2013-10-13 20:24:49.156 myApp[43197:c07] ================> result: 1
2013-10-13 20:24:49.157 myApp[43197:c07] ================> new result: 1
Is there a way to update the stubbed value without having to stop mocking and/or create a new mock object?
Use expect instead of stub. AFAIK it's not possible to stub a method twice with OCMock. You don't need to send verify after executing the code you want to test since you are not interested in verifying any expectations.

QDialog closing crash

I have problem in ensuring the dialog is closed/released with the following Qt codes.
//Segment 1: To open a 'wait' dialog for some long-running tasks
void MainWindow::ui_showProgressDialog(QString title) {
dlgProgress = new QProgressDialog(title, tr("Cancel"), 0, 0, this);
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); // line 1
dlgProgress->setModal(true);
dlgProgress->show();
connect(voidWatcher, SIGNAL(finished()),
this, SLOT(onPopulationFile()));
}
//Segment 2: Attempts to close the 'wait' dialog
void MainWindow::onPopulationFile() {
qDebug((dlgProgress == NULL) ? "true" : "false");
if (dlgProgress) //
{
qDebug("0");
dlgProgress->close(); // line 2
qDebug("1");
}
qDebug((dlgProgress == NULL) ? "true" : "false");
}
Issue: When I trigger the call 'ui_showProgressDialog' twice, the second call always crash my program. Originally, my code has no line 1 of segment 1, and from the QtCreator, it always crashes on line 2 of segment 2. Debug message shows as follow
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
*** CRASH ***
I read the documentation that NEVER delete objects from different threads, I'm doubt that the call 'onPopulationFile' is invoked from a non-main thread. So I added the line 1 to segment to let the program decide when the delete the object. But it seems not work. Any suggestion to the problem?
Experiment done: If I replace QProgressDialog with QDialog, the program goes without crashes, and the debug message show
// first call to onPopulationFile
false
0
1
false
// second call to onPopulationFile
false
0
1
false
So,
Why the second null test in segment 2 always fail? [Edit: I have to explicitly set the variable to NULL]
Is there any better way to close the 'wait' dialog?
I try to close/release the dialog as I want release memory as soon as possible. Do I really need to manually delete the dialog?
Platform: Qt Opensource 4.8 (x64), Windows 7 (x64), MinGW (rubenvb 4.7.2)
dlgProgress->setAttribute(Qt::WA_DeleteOnClose); deletes the widget when it is closed. As you are calling dlgProgress->close();, after this line the object it points to has been freed, and dlgProgress is now a invalid pointer.
You need to set dlgProgress to null after any call to close, or event better, use the signal Qobject::destroyed().
EDIT:
Qt::WA_DeleteOnClose specify that the object will be deleted if a close event happens. Not exactly how much time it will take. For instance if they are using QObject::deleteLater(), then the object is not deleted right away. Even if it is not the case , pieces of code like
A* a = new A;
a->dosomething();
delete a;
a->dosomething();
are undefined behavior. The second call to a->dosomething(); may crash (if you are lucky) or may not crash.

Core Data, problems when saving or retrieving, don't know where it is

I'm quite new with Core Data, and I'm having an issue that I don't understand. I don't know what's going wrong.
I'm saving into my Persistent Store, 7 objects of an entity "Weight" that is read from a JSON file with this code:
for (NSDictionary *values in aWeightValues)
{
weightValues = [NSEntityDescription insertNewObjectForEntityForName:#"Weight"
inManagedObjectContext:moc];
[weightValues setValue:[typeWeight objectForKey:#"unit"] forKey:#"unit"];
[weightValues setValue:[values objectForKey:#"timestamp"] forKey:#"date"];
[weightValues setValue:[values objectForKey:#"value"] forKey:#"amount"];
if (![moc save:&error])
{
NSLog(#"Problem saving: %#", [error localizedDescription]);
}
}
The for loop makes 7 loops, that means it's being saved correctly (speaking about the number of objects).
But then, when I try to retrieve data from the Persistent Store in this way:
-(NSMutableArray *) extractWeightEntities
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
NSError *error;
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSEntityDescription *entityWeight = [NSEntityDescription entityForName:#"Weight" inManagedObjectContext:moc];
NSFetchRequest *request = [[[NSFetchRequest alloc]init]autorelease];
[request setEntity:entityWeight];
entityWeight = nil;
fetchResult = [[moc executeFetchRequest:request error:&error]mutableCopy];
return (fetchResult);
}
and try to show one attribute of each object retrieved, I get 1044 rows in my TableView!! when I should have just 7.
What am I doing wrong? Is the problem when I'm saving, or when I'm retrieving?
I hope you can help to solve this issue. Many thanks in advance!!
You don't need to call save on each iteration of the loop, this is very inefficient. Save afterwards.
Put a breakpoint on you loop and ensure it is only going over it 7 times.
Is the data continuously accumulating? Are you deleting the app each time? If you keep running the code - it will keep adding objects to your datastore unless you check if they exist in the datastore before inserting them.

Possible to create random numbers in SASS / Compass?

I'm working on a project where I utilize SASS and Compass and need to somehow come up with some random numbers in the CSS file. Specifically, I need some floating point numbers between 0 and 1. Is this possible with SASS and Compass alone?
This is very possible if you create a sass function since sass is ruby its as easy as opening the functions module and injecting your random function
module Sass::Script::Functions
module MyRandom
def random
rand(1.0)
end
end
include MyRandom
end
require the file after sass has loaded
Then in your stylesheet
$my-randome-number: random();
Yes, as Scott said, it is possible, but I am not a Rails programmer, so I just wanted to copy and paste the code but first I did not know where to place the Code and then it did not work.
I had to play around with the snipped and expanded it to more Flexibility that I had need for:
module Sass::Script::Functions
module USW_Random
## Create random Color
# inspired by: http://victorcoulon.fr/generating-random-color-in-sass/
#
def usw_randomColor()
Sass::Script::Color.new([rand(255), rand(255), rand(255)])
end
## Create random Number
# int max [optional] if max is not supplied a float between 0 and 1 is returned.
# if max is supplied, an Integer between 0 and max (both inclusive) will be returned.
# int min [optional] if min is supplied too, an Integer between min and max (both inclusive) will be returned.
#
def usw_random(max=-1, min=0)
Sass::Script::Number.new( max.to_i < 0 ? rand() : rand(min.to_i .. max.to_i ))
end
end
include USW_Random
end
Ths can be used in a SCSS file like this:
#debug usw_random();
#debug usw_random(10);
#debug usw_random(8, 2);
#debug usw_randomColor();
and will printout:
xxx.scss:25 DEBUG: 0.42782
xxx.scss:26 DEBUG: 3
xxx.scss:27 DEBUG: 5
xxx.scss:28 DEBUG: #e7c00b
I also did not know where to put the Code for this. I use SASS within compass framework. You can place this Code directly into your Compass Config.rb file.
Or you put it in another file and only put this line into your Compass Config.rb file:
## my "own" ruby functions.
require "../SASS/RUBY/at.usw.rb"
Update: With Sass 3.3 (2014), there is now a built-in random() function:
http://sass-lang.com/documentation/Sass/Script/Functions.html#random-instance_method
$number: random()
You can also build your own simple seeded random function in Sass. Example (SCSS):
/* YOUR SEED HERE: */
$seed: 369;
#function getRandom($max) {
//http://indiegamr.com/generate-repeatable-random-numbers-in-js/
//Note the "!global" flag:
//http://webdesign.tutsplus.com/articles/understanding-variable-scope-in-sass--cms-23498
$seed: ($seed * 9301 + 49297) % 233280 !global;
#return ($seed / 233280) * $max;
}
.my-class {
height: getRandom(200) + px;
opacity: getRandom(1);
}
http://codepen.io/Sphinxxxx/pen/Gpmmye

Resources