Does anyone on Scratch know objective-c that is used for iphone apps and itouch apps?????
If you do, can I ask you for some help.... my problem/situation is that I need to know how to delete just the last character in a string....
my current code for it is
-(IBAction) clickDelete {
[displayString replaceCharactersInRange: [displayString length] withString: @" "]];
[display setText: displayString];
}
If you can help, I will be thankful.
Thanks,
Technoman
Offline
Hi,
You're providing the wrong parameters to your methods, and the methods you're using are probably not what you want.
technoman wrote:
-(IBAction) clickDelete {
[displayString replaceCharactersInRange: [displayString length] withString: @" "]];
[display setText: displayString];
}
NSString's replaceCharactersInRange method accepts an NSRange, but you're only providing it with an integer (the length). replaceCharactersInRange doesn't delete characters, it replaces them - you could replace the character you want to delete with a blank space (as you're trying to do), but you're not deleting the character - the length of the string remains the same.
Since you want to delete a character directly from a string, you can't use NSString, since it's an immutable object - you instead need to use its subclass, NSMutableString.
NSMutableString has a deleteCharactersInRange method, which accepts an NSRange as a parameter. If you're unsure about what an NSRange is, check the XCode docs.
So, to fix it you'd need to create your string as an NSMutableString, create an NSRange indicating which characters you'd like to be removed, and then run the deleteCharactersInRange method.
If none of that made much sense, it might be best to read (or re-read) the NSString documentation or perhaps even one of the several good online Obj-C tutorials. There are also some helpful forums, particularly the Apple Developer forums and a couple of other iPhone SDK sites.
Last edited by lxt (2009-07-18 20:34:21)
Offline
technoman wrote:
Does anyone on Scratch know objective-c that is used for iphone apps and itouch apps?????
If you do, can I ask you for some help.... my problem/situation is that I need to know how to delete just the last character in a string....
my current code for it is
-(IBAction) clickDelete {
[displayString replaceCharactersInRange: [displayString length] withString: @" "]];
[display setText: displayString];
}
If you can help, I will be thankful.
Thanks,
Technoman
Mac(Cocoa) apps too. Sorrry I can't help, I haven't done anything with it recently.
Offline
technoman wrote:
Nevermind, I used the expression [displayString deleteCharactersInRange: NSMakeRange ([displayString length] - 1, 1)];.... so I don't need help anymore.
You mean the one I said in my post?
lxt wrote:
NSMutableString has a deleteCharactersInRange method, which accepts an NSRange as a parameter. If you're unsure about what an NSRange is, check the XCode docs.
Offline
I am currently starting iPhone development.. I just finished my first app.. it very simple, its called lunch money which will calculate how much money you owe for your lunches...
My company is web geeks http://web-geeks.com our site is currently under development though.. do you make games, technoman?
Offline
techy wrote:
I am currently starting iPhone development.. I just finished my first app.. it very simple, its called lunch money which will calculate how much money you owe for your lunches...
My company is web geeks http://web-geeks.com our site is currently under development though.. do you make games, technoman?
I am not making a game at the moment but I will be once I finish my scientific/ financial/fraction calculator which takes some time. is your app on the app store???
Offline
technoman wrote:
techy wrote:
I am currently starting iPhone development.. I just finished my first app.. it very simple, its called lunch money which will calculate how much money you owe for your lunches...
My company is web geeks http://web-geeks.com our site is currently under development though.. do you make games, technoman?I am not making a game at the moment but I will be once I finish my scientific/ financial/fraction calculator which takes some time. is your app on the app store???
Nice, I submitted my app a couple days ago, i heard it takes a few weeks to get on the app store... I am trying to start game development.. but I just started a couple weeks ago... What do you suggest i should learn for game development on iphone, c, c++, objective C, openGL ES, openAL?
Also what company do you have for your iphone apps?
Offline