When i added the code(textField.text=preTotalNumber;) in the method(onButtonPressed),the failure appeared.
Can anyone please help me?thk
preTotalNumber should be an NSString, and if not you should convert it to NSString. for instance if it's an integer you can use the following:
[NSString stringWithFormat:#"%d", preTotalNumber];
Related
Here's the code for my paint method in my Win32 project:
case WM_PAINT:
_tcscat_s(greeting, sizeof(greeting), LoadedFile);
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,
5, 5,
greeting, _tcslen(greeting));
EndPaint(hWnd, &ps);
break;
I am consistently getting the error that either the stack around greeting or around ps is corrupted. To be clear, greeting is initialized like:
TCHAR greeting[100] = _T("Welcome! Your file is ");
And LoadedFile is initialized like this:
TCHAR LoadedFile[100];
LoadedFile[0] = 0;
LoadedFile is not yet changed by anything, so it shouldn't be adding anything to greeting. I've tried things like
sizeof(greeting) + 1
Which just shifts the error. Not sure what's wrong here.
Edit: Without the _tcscat_s(), call the window loads normally
Well, I found the problem, even though I don't really understand why the solution works. I just changed
_tcscat_s(greeting, sizeof(greeting), LoadedFile);
to
_tcscat_s(greeting, 100, LoadedFile);
just making a basic game and used the NSUserDefaults to save the high score. while calling the i needed to use a NSString with a Format of "Best Time : %i". I Ran the game on the simulator and it worked perfectly.
However when I went to run it on the device the label that i formatted using the NSString(format "Best Time : %i") did not work nothing appeared in the label?
Here is the code I used for calling the saved Best time:
//The previous games best time
var highscoreDefaults = NSUserDefaults.standardUserDefaults()
if (highscoreDefaults.valueForKey("Highscore") != nil){
theNewTime = highscoreDefaults.valueForKey("Highscore") as! NSInteger!
thehighscore.text = NSString(format: "Best Time : %i" , theNewTime) as String
}
//---------------------
You can use Swift's string interpolation as you don't need any advanced features from the C-format specifier:
thehighscore.text = "Best Time : \(theNewTime)"
Can someone help with resolving this error?
QString *description = new QString;
description = *dialog.descriptionEdit->toPlainText();
error: no match for 'operator*' in '*QTextEdit::toPlainText() const()'
and when I try:
QString *description = new QString;
description = dialog.descriptionEdit->toPlainText();
error: cannot convert 'QString' to 'QString*' in assignment
You need this
*description = dialog.descriptionEdit->toPlainText();
otherwise you are assigning to the pointer not the object it points to. description is a pointer to QString, *description is a QString.
I just started coding and as I followed Apple's article 'Your Second iOS App:Storyboard', I had a warning that says 'incompatible pointer types initializing Birdsighting *__strong with an expression of type NSString *' from the following code:
detailViewController.sighting = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
well you are trying to say (IT SEEMS):
NSString *stringInCurrentTableViewRow = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];
BirdSighting *yourObject = stringInCurrentTableViewRow;
you are sure the dataController doesnt contain Strings ;)
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.