Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 3, 2006, 07:26 PM   #1
HungrySeacow
macrumors regular
 
Join Date: Jan 2006
Location: West Palm Beach
NSTimer to scroll text into a textField?

I have been trying to figure out how to get text to scroll into a textField. I thought that I might be able to do with an NSTimer that calls a method which would increase an NSString one character at a time and then set the value of the textField to the string before the NSTimer would fire again. However, I feel clueless with this. Anyone think they could help me out with this?
__________________
|||||| YummySoup! - Recipe management and sharing at its best!
HungrySeacow is offline   0 Reply With Quote
Old Mar 3, 2006, 08:30 PM   #2
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Just a quick off-the-top-of-my head to give you ideas...

Code:
- (void) methodCalledByTimer
{
     [[textView textStorage] appendAttributedString:[[[NSAttributedString alloc] initWithString:@"a"] autorelease]];
}
Catfish_Man is offline   0 Reply With Quote
Old Mar 3, 2006, 09:00 PM   #3
HungrySeacow
Thread Starter
macrumors regular
 
Join Date: Jan 2006
Location: West Palm Beach
Quote:
Originally Posted by Catfish_Man
Just a quick off-the-top-of-my head to give you ideas...

Code:
- (void) methodCalledByTimer
{
     [[textView textStorage] appendAttributedString:[[[NSAttributedString alloc] initWithString:@"a"] autorelease]];
}
Thanks for the idea.
I was wondering why you choose an NSAttribuitedString rather then an NSString?

I tested out the code under my IBAction method for the button that activates the sequence bypassing the NSTimer to see if I could get it to work but I get an error when the method is called, "-[NSTextField textStorage]: selector not recognized [self = 0x31c4c0]". I so tried a setup using an NSString instead but got a similar selector error. I just finished reading a few cocoa books and am still having trouble figuring out how to create code myself. At least I now know what polymorphism means, LOL. Any help is greatly appreciated .
__________________
|||||| YummySoup! - Recipe management and sharing at its best!
HungrySeacow is offline   0 Reply With Quote
Old Mar 4, 2006, 03:22 AM   #4
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
You may be interested in this link on scrolling views Link.
And also the example here
caveman_uk is offline   0 Reply With Quote
Old Mar 4, 2006, 12:26 PM   #5
HungrySeacow
Thread Starter
macrumors regular
 
Join Date: Jan 2006
Location: West Palm Beach
Quote:
Originally Posted by HungrySeacow
Thanks for the idea.
I was wondering why you choose an NSAttribuitedString rather then an NSString?

I tested out the code under my IBAction method for the button that activates the sequence bypassing the NSTimer to see if I could get it to work but I get an error when the method is called, "-[NSTextField textStorage]: selector not recognized [self = 0x31c4c0]". I so tried a setup using an NSString instead but got a similar selector error. I just finished reading a few cocoa books and am still having trouble figuring out how to create code myself. At least I now know what polymorphism means, LOL. Any help is greatly appreciated .
Ahh, I am a dumba**, I looked at the documentation and see that textStorage is for textViews and not textFields. I now have this and it is working:
Code:
mutableString = [[NSMutableString alloc] initWithString:@"string to apend to."];
	[mutableString appendString:[[[NSMutableString alloc] initWithString:@"a"] autorelease]];
	[textField1 setStringValue: mutableString];
Thanks again for helping! Now I will try and figure out how to get this in a loop or so to do what I am looking for.
__________________
|||||| YummySoup! - Recipe management and sharing at its best!
HungrySeacow is offline   0 Reply With Quote
Old Mar 4, 2006, 01:12 PM   #6
HungrySeacow
Thread Starter
macrumors regular
 
Join Date: Jan 2006
Location: West Palm Beach
Yay! I got what I wanted to work! Thanks again Catfish Man for leading me down the right path! Here is the code that I ended up with:
Code:
#import "AppController.h"

@implementation AppController


- (IBAction)start:(id)sender
{
	stringData = [[NSString alloc] initWithString:@"String to be scrolling :)"];
	mutableString = [[NSMutableString alloc] initWithString:@""];
	x = 0;
	timer = [NSTimer scheduledTimerWithTimeInterval:0.2
											 target:self
										   selector:@selector(changeText)
										   userInfo:nil
											repeats:YES];
}

- (void)changeText
{
    theChar = [stringData characterAtIndex:x];
	intermediateMutableString = [NSMutableString stringWithCharacters:&theChar length:1];
	[mutableString appendString:intermediateMutableString];
	[textField1 setStringValue: mutableString];
	x++;
	if ([mutableString length] == [stringData length]) {
		[timer invalidate];
	}
}

@end
EDIT: Oh I forgot to ask what this warning was about that I get from the compiler from this line: "intermediateMutableString = [NSMutableString stringWithCharacters:&theChar length:1];"
The warning is: "warning: passing argument 1 of 'stringWithCharacters:length:' from incompatible pointer type". The program works as I wanted at least.
__________________
|||||| YummySoup! - Recipe management and sharing at its best!
HungrySeacow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Dreamweaver CS4 Scrolling text area in page Cub Web Design and Development 4 Apr 1, 2011 12:09 AM
How to embed video into a e-mail raphael1982 Mac Basics and Help 1 Nov 8, 2010 05:29 PM
Applescript to paste text into safari Problem SChaput Mac Programming 1 Jul 28, 2010 04:06 PM
Change OS X scroll bar, into iTunes scroll bar applefan69 OS X 2 Oct 1, 2008 11:24 PM
how can i add scroll bar to the text box chidambaram Mac Programming 1 Mar 28, 2008 06:19 AM


All times are GMT -5. The time now is 03:31 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC