Why am I getting this when I do a NSLog? - ios6

This is the line of code for my NSLog:
NSLog(#"\n\noCLientFirstName: %#\nlastName: %#\nconcatenatedName: %#",oClientFirstName, lastName, concatenatedName);
Why am I getting output that looks like this?
oCLientFirstName: <UITextField: 0xefe0330; frame = (394 293; 160 30); text = 'Bob'; clipsToBounds = YES; opaque = NO; autoresize = TM+BM; gestureRecognizers = <NSArray: 0xefe12d0>; layer = <CALayer: 0xefe0120>>
lastName: <UITextField: 0xef05bd0; frame = (20 40; 260 40); text = 'Jones'; clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0xef057c0>; layer = <CALayer: 0xef05ba0>>
concatenatedName: Bob<UITextField: 0xef05bd0; frame = (20 40; 260 40); text = 'Jones'; clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0xef057c0>; layer = <CALayer: 0xef05ba0>>
I have NEVER had this issue before; the output should look like this:
oClientFirstName: Bob
lastName: Jones
concatenatedName: BobJones
What's going on?

%# format specifier in NSLog will call the following methods in order on the object parameter for the position.
debugDescription
description
You're getting the result of that for the objects.

This looks like you are passing UITextField objects to your log function rather than NSStrings. Double check the types and adjust your code accordingly.

NSLog(#"\n\noCLientFirstName: %#\nlastName: %#\nconcatenatedName: %#",oClientFirstName.text, lastName.text, concatenatedName.text);
this is the solution of your question :)

Related

Matlab, AppDesigner-Convert image on a good type and use it in "imread" function

I use AppDesigner inMATLAB to show photos with changed RGB. But there is the problem with character of the photo.
When I switch on my own fuction "changeRGB", finally "choosenImage" has 20bytes, class "char" and size(1x10). OK!
There is no problem in using the "function OpenButtonValueChanged". OK!
There is the problem with "function UploadButtonPushed". OK!
ABOUT THE PROBLEM:
When I click button which callback is "function UploadButtonPushed" I get the error:
"Error using imread>parse_inputs (line 502)
The file name or URL argument must be a character
vector or string scalar."
"Error in imread (line 342)
[source, fmt_s, extraArgs, was_cached_fmt_used] =
parse_inputs(cached_fmt, varargin{:});"
WHY?
Because in the "function UploadButtonPushed" my choosenImage has 1977624bytes, class "uint8" and size(681x968x3). So it's too bug for "imread".
WHAT I TRIED:
When in "function OpenButtonValueChanged" I convert a photo, adding "char": (myimage = char(app.clickedImage)); the class of the photo is changing from uint8 to char but the size.
When I use "num2cell", the claas of the photo is changing on "cell" but size and number of bytes are the same- so big. And I get the Error: "Error using imread>parse_inputs (line 502) The file name or URL argument must be a character vector or string scalar."
In my own function "changeRGB" I used "imread(image)" and here is the problem with the size of the photo. Do you know how to get the correct one?
%my own properties in AppDesigner- to use them in different functions
properties (Access = public)
clickedImage;
addR = 1;
addG = 1;
addB = 1;
end
%first function in AppDeesigner
function OpenButtonValueChanged(app, event)
value = app.OpenButton.Value;
[file, howManyFiles] = chooseImagesFromComputer; %myown function
%I load 3 images which are showed as miniatures
myFile1 = imread(file{1});
imshow(myFile1, 'Parent', app.UIAxes1_1);
myFile2 = imread(file{2});
imshow(myFile2, 'Parent', app.UIAxes1_2);
myFile3 = imread(file{3});
imshow(myFile3, 'Parent', app.UIAxes1_3);
%take values of changed RGB from the slider
app.addR = app.SliderR.Value
app.addG = app.SliderG.Value
app.addB = app.SliderB.Value
%work only on one image to change its colors. app.clickedImage, app.addR, app.addG, app.addB are properties at the beginning of the code
app.clickedImage = file{1};
app.clickedImage = changeRGB(app.clickedImage,app.addR,app.addG,app.addB); %changeRGB- my own function- here is the problem. I add it bottom
imshow(app.clickedImage,'Parent',app.UIAxesMain);
end
%second function in AppDesigner
%here is the button to upload color of the photo
function UploadButtonPushed(app, event)
myimage = app.clickedImage;
myimage = changeRGB(myimage,app.addR,app.addG,app.addB);
imshow(myimage);
end
%here is my own function in matlab, not in AppDesigner, which makes problem:
function [changedImage] = changeRGB(choosenImage, addR, addG, addB)
whos
loadedImage = imread(choosenImage);
R = loadedImage(:,:,1); %extract one of the color channels
G = loadedImage(:,:,2);
B = loadedImage(:,:,3);
RBG = cat(3,R,G,B);
R_adj2 = R + addR;
G_adj2 = G + addG;
B_adj2 = B + addB;
changedImage = cat(3,R_adj2,G_adj2,B_adj2);
end
First, you make unnecessary operations in changeRGB
function [changedImage] = changeRGB(choosenImage, addR, addG, addB)
loadedImage = imread(choosenImage);
loadedImage = bsxfun(#sum, loadedImage, reshape([addR, addG, addB], [1 1 3]);
end
Then this function return an array (the modified image) so in UploadButtonPushed(app, event) when you run myimage = app.clickedImage;, you are passing the modified array instead of the image path, that you set here app.clickedImage = changeRGB(app.clickedImage,app.addR,app.addG,app.addB);
So you have to change the design of your variables, because app.clickedImage is saving either the image path, or the image itself. Consider having 2 different variables.
A good advice also is to use matlab debugger which is really good help to find the source of this kind of problems.

Retrieving datas within an Array

This is probably easy but I just cannot get the answer. Here is a simple Array:
I want the information to be distributed from an Input textBox to different dynamic textBox after a click. I am OK with buttons.
var ERLQ1:Array = ["ERLQ1", "N09°02.61 / E100°49.11", "ErawanLq"];
InputText = "ERLQ1";
//I want to display:
Txt1 = "ERLQ1" //Being first part of the array as main reference.
Txt2 = "N09°02.61 / E100°49.11" // Should be: String(ERLQ1[1])
Txt3 = "ErawanLq" // Should be: String(ERLQ1[2])
First time I write in a forum like this. Please forgive if not perfect. Thanks in advance.
Andre
If I understand correctly, an array of objects would work well. Since you have a set number of textfields I assume that you also have a set number of details that you want to display in them. If that is the case, this solution should work fine.
arr:Array = [{_name:"ERLQ1",ans1:"N09°02.61 / E100°49.11",ans2:"ErawanLq"},
{_name:"ERLQ2",ans1:"question 2 answer 1",ans2:"ques2ans1"}];
So, I don't really "get" your application, but if it were some sort of a quiz, you'd have a new array element for each question, and that element has a name, and two answers. Easy to modify it to grab answers from an answer pool. Now to find the element in the array that has ._name == "ERLQ1" you will need to loop through all the elements and return the one that has the ._name property that matches your search. Here is an example function:
private function matchName(arr:Array, term:String):int{
for (var i:int = 0; i < arr.length; i++){
if (arr[i]._name == term){
return i;
}
}
return -1;
}
This function will return the array index number of the matching term. If no match exists, it returns -1. So you could use it like this (pseudocode):
// on submit search{
// find the index number in the array of the element that matches the search term
var ind:int = matchName(arr, searchTerm);
// assign the textfield texts to the corresponding associated values
textBox1:text = arr[ind]._name;
textBox2:text = arr[ind].ans1;
textBox3:text = arr[ind].ans2;
}
I perhaps misunderstood (because of my English), but :
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
var ERLQ1:Array = ["ERLQ1", "N09°02.61 / E100°49.11", "ErawanLq"];
var Txt1 : TextField = new TextField();
Txt1.autoSize=TextFieldAutoSize.CENTER;
Txt1.type = TextFieldType.INPUT;
Txt1.border = true;
var Txt2 : TextField = new TextField();
Txt2.autoSize=TextFieldAutoSize.CENTER;
Txt2.type = TextFieldType.INPUT;
Txt2.border = true;
var Txt3 : TextField = new TextField();
Txt3.autoSize=TextFieldAutoSize.CENTER;
Txt3.type = TextFieldType.INPUT;
Txt3.border = true;
addChild(Txt1);
addChild(Txt2);
addChild(Txt3);
Txt1.x = 20, y =40;
Txt2.x = 180, y =40;
Txt1.x = 300, y =40;
Txt1.text = ERLQ1[0]; // is now : first part of the array as main reference (String(ERLQ1[0]).
Txt2.text = ERLQ1[1]; // is now : String(ERLQ1[1]);
Txt3.text = ERLQ1[2]; // is now : String(ERLQ1[2]);
This will display 3 TextFiels as input text like this :
If I misunderstood your question, please tell me more about what You expect!
Best regards.
Nicolas

Sorting NSMutableArray with NSDictionaries that contains Numbers as String?

Have a little Problem and can´t find a working solution :(
I have a NSMutableArray like:
{
Entfernung = 129521;
"Event_DATE" = "2014-03-23";
"Event_ID" = 1;
"Event_KAT" = 1;
"Event_NAME" = achtzehn;
},
{
Entfernung = 112143;
"Event_DATE" = "2014-03-24";
"Event_ID" = 2;
"Event_KAT" = 2;
"Event_NAME" = neunzehn;
}
How can i sort this Array with the object "Entfernung"?
Thx 4 help!
Gerhard
Try something like this;
NSArray *stuff = .... //your array here;
NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:#"Entfernung" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
//depending on the number stored in the string, you might need the floatValue or doubleValue instead
NSNumber *num1 = #([(NSString*)obj1 integerValue]);
NSNumber *num2 = #([(NSString*)obj2 integerValue]);
return [num1 compare:num2];
}];
NSArray *sortedStuff = [[stuff sortedArrayUsingDescriptors:#[sorter]];
The easiest I'd say would be to define a compare method on Entfernung class and then use - (void)sortUsingSelector:(SEL)comparator If you already have a function which accepts two objects (say your NSDictionary object) then I'd do the sort like this - (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context
Give a man a fish, and he can eat today. Tell him how to fish, and he has to do the work himself for the rest of his life...
In Xcode, look at the help menu. In the help menu, you find an item "Documentation and API reference". There you type in "NSMutableArray", then you search for "sort". Which gives you five methods:
– sortUsingDescriptors:
– sortUsingComparator:
– sortWithOptions:usingComparator:
– sortUsingFunction:context:
– sortUsingSelector:
You can click on each one and read the description. The most straightforward to use is sortUsingComparator: which comes with a nice bit of sample code that you adapt for your purposes.

BCB6: How to put elements of a form in an array?

I'm building a simple game in C++Builder6 and I have 42 Image objects on a Form... At start-up I want all Image objects to be disabled, so I wonder can I put all of them in an array and simply loop thorough the entire array and make them Disabled? I know there must be a way, but I'm just new to programming :)
You have several options.
First: You can declare
Image* array[40];
And dynamically construct the image.
for ( int i = 0 ; i < 40; ++i ) {
image[i] = new Image(this); // where "this" is pointer to your form
image[i]->Parent = this;
// option below are optional
image[i]->Height = 50;
image[i]->Width = 50;
image[i]->Left = 40;
image[i]->Top = 100;
image[i]->Tag = i;
image[i]->OnClick = ButtonClick; // connect with method
}
Second option is declare
Image* array[40];
and manually set all values;
array[0] = Image1;
...
array[39] = Image40;
Then you will have all image in array and you can use loop for doing something on all Image

How can I store SpaceManager cpShape's in something like an array?

I'm trying to create a squishy ball with Cocos2d and Chipmunk (via SpaceManager) using a bunch of rects all chained together then joined with springs to a central body.
Something like these examples
But in order to do this, i think I need to store all the cpShapes in an array after I've created them so I can then loop through the array to link them all together with constraints.
However, when i try to put cpShapes in an array, I get an error telling me it's an "incompatible pointer type". So... I either need to use something other than an array (I've tried a set, that didn't work either) or I need to do something to the shape to make it compatible... but what? OR I need another aproach.
Any ideas?
Here's the code so far should it be relevant...
- (id) init
{
if ( (self = [super init]) ) {
SpaceManager * spaceMgr = [[SpaceManager alloc] init];
[spaceMgr addWindowContainmentWithFriction:1.0 elasticity:1.0 inset:cpv(5, 5)];
// This is a layer that draws all the chipmunk shapes
ChipmunkDrawingLayer *debug = [[ChipmunkDrawingLayer node] initWithSpace:spaceMgr.space];
[self addChild:debug];
int ballPeices = 10; // the number of peices I want my ball to be composed of
int ballRadius = 100;
float circum = M_PI * (ballRadius * 2);
float peiceSize = circum / ballPeices;
float angleIncrement = 360 / ballPeices;
CGPoint origin = ccp(240, 160);
float currentAngleIncrement = 0;
NSMutableArray *peiceArray = [NSMutableArray arrayWithCapacity:ballPeices];
for (int i = 0; i < ballPeices; i++) {
float angleIncrementInRadians = CC_DEGREES_TO_RADIANS(currentAngleIncrement);
float xp = origin.x + ballRadius * cos(angleIncrementInRadians);
float yp = origin.y + ballRadius * sin(angleIncrementInRadians);
// This is wrong, I need to figure out what's going on here.
float peiceRotation = atan2( origin.y - yp, origin.x - xp);
cpShape *currentPeice = [spaceMgr addRectAt:ccp(xp, yp) mass:1 width:peiceSize height:10 rotation:peiceRotation];
currentAngleIncrement += angleIncrement;
[peiceArray addObject:currentPeice]; //!! incompatible pointer type
}
spaceMgr.constantDt = 0.9/55.0;
spaceMgr.gravity = ccp(0,-980);
spaceMgr.damping = 1.0;
}
return self;
}
The incompatible pointer type is easy to explain :)
[NSMutableArray addObject] is defined as such:
- (void)addObject:(id)anObject
So what is an id then? Great question! Remember, Objective-C is still C at it's core. According to the Objective-C Programming Guide
typedef struct objc_object {
Class isa;
} *id;
That's great, now we know about *id but what about id itself? That's what is referenced in the method signature. For that, we have to look at objc.h
typedef id (*IMP)(id, SEL, ...);
Clearly, cpSpace* doesn't fit that, so you'll be getting incompatible pointer type if you try to put those into NSMutableArray using that message.

Resources