Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-20-2011, 11:23 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 7
cs_iris is on a distinguished road
Default concatenating buttons(string)

Hello! I am a newbie in developing apps in iphone and I have a problem with our first project. It is a calculator but with a different touch. We are going to solve the equality of trigonometric functions, but before we can do the comparison in solving the equality, I must solve the concatenating problem. I cannot concatenate the strings coming from the buttons. For example, button1 = "cos"; button2 = "x". When I click the button1, the screen will show cos, but when I click button2 the string "cos" in the screen will be replaced by the string "x" of button2. What should I do to concatenate them? I think stringAppendingByString will not be the solution, I already tried it and it did not work.
cs_iris is offline   Reply With Quote
Old 09-20-2011, 01:15 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by cs_iris View Post
Hello! I am a newbie in developing apps in iphone and I have a problem with our first project. It is a calculator but with a different touch. We are going to solve the equality of trigonometric functions, but before we can do the comparison in solving the equality, I must solve the concatenating problem. I cannot concatenate the strings coming from the buttons. For example, button1 = "cos"; button2 = "x". When I click the button1, the screen will show cos, but when I click button2 the string "cos" in the screen will be replaced by the string "x" of button2. What should I do to concatenate them? I think stringAppendingByString will not be the solution, I already tried it and it did not work.
The NSString class has a bunch of methods that let you combine strings.

My guess is that you really want a method like stringWithFormat. That takes a C style format string (but with added format specifiers that are specific to Objective C) and lets you create a new string from the format string plus other inputs.

For example, you might write code like this:

Code:
NSString* functionString = field1.text;
NSString* variableString = field2.text;

NSString expressionString = 
  [NSString stringWithFormatString: @"%@(%@)",
  functionString, 
  variableString];
If function string was "cos" and variableString was "x" expressionString would contain "cos(x)" after the above code was run.

The "%@" in the format string means "replace this entry with the value of an object." You usually use it to insert strings into other strings.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-21-2011, 06:40 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 7
cs_iris is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
The NSString class has a bunch of methods that let you combine strings.

My guess is that you really want a method like stringWithFormat. That takes a C style format string (but with added format specifiers that are specific to Objective C) and lets you create a new string from the format string plus other inputs.

For example, you might write code like this:

Code:
NSString* functionString = field1.text;
NSString* variableString = field2.text;

NSString expressionString = 
  [NSString stringWithFormatString: @"%@(%@)",
  functionString, 
  variableString];
If function string was "cos" and variableString was "x" expressionString would contain "cos(x)" after the above code was run.

The "%@" in the format string means "replace this entry with the value of an object." You usually use it to insert strings into other strings.
Thank you for the quick reply, but I still have a problem. This is what happens after I put the code...

Screen shot 2011-09-21 at 7.28.48 PM.jpg

I really don't know what to do next..

*we've finished the code already but in java form
cs_iris is offline   Reply With Quote
Old 09-21-2011, 06:49 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You forgot the *
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-21-2011, 06:57 AM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by BrianSlick View Post
You forgot the *
How could you tell from that absurdly small image? I'm impressed.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-21-2011, 07:24 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

If you tap it, it's almost large enough.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-21-2011, 08:05 AM   #7 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 7
cs_iris is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You forgot the *
I was about to edit my reply, because this is what happens.. i got the wrong image...
Screen shot 2011-09-21 at 8.56.03 PM.jpg

and it is still the same.. 'cos' was replaced by 'x' in the screen...
cs_iris is offline   Reply With Quote
Old 09-21-2011, 08:08 AM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

See the troubleshooting link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 09-21-2011, 08:34 AM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by cs_iris View Post
I was about to edit my reply, because this is what happens.. i got the wrong image...
Attachment 3623

and it is still the same.. 'cos' was replaced by 'x' in the screen...
Please post bigger images, and the code that the image shows as text in code blocks. I can't read those tiny images.

I can't read the code in the screen-shot you posted, but I can see that you have at least 4 warnings. Those warnings tell you that something is wrong with your code. Fix them and your problems may well go away.


Ignoring compiler warnings is a very bad idea, especially if you don't understand the reason for them. I have had to live with warnings in a project because they were caused by code that was out of my control, but other than that, our company has a zero tolerance policy for compiler warnings.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 09-21-2011 at 08:38 AM.
Duncan C is offline   Reply With Quote
Old 09-22-2011, 02:00 AM   #10 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 7
cs_iris is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
See the troubleshooting link in my signature.
The link was kinda helpful. Thanks!
But I didn't get the local declaration..hides instance variable. I followed the answer but the problem is that it makes the new declared variable unused... And when I fixed the unused, the problem with the local declaretion appears again. What should I do?
cs_iris is offline   Reply With Quote
Old 09-22-2011, 04:50 AM   #11 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by cs_iris View Post
The link was kinda helpful. Thanks!
But I didn't get the local declaration..hides instance variable. I followed the answer but the problem is that it makes the new declared variable unused... And when I fixed the unused, the problem with the local declaretion appears again. What should I do?

Post the code that is showing the "local declaration hides instance variable" warning. Not an illegible screen-shot, the code, inside a code block. Tell us in words which line is giving the warning, and also a description of what the code does that is wrong.

Also post the .h file for the module who's code you are posting.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
buttons, concatenate, strings

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
15 members and 384 guests
7twenty7, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:14 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0