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

Similar Threads
thread Thread Starter Forum Replies Last Post
Issue with Two Finger scroll and Performance MX scroll direction clocksmith25 MacBook Pro 3 Dec 11, 2013 02:58 AM
Resolved: scroll view doesn't scroll in certain area straber iPhone/iPad Programming 8 Mar 22, 2013 01:36 PM
Looking for an application that can scroll custom text over video. cymro Mac Applications and Mac App Store 0 Oct 6, 2012 07:42 AM
Have you noticed when you scroll down through your list of text conversations TH55 iPhone 11 Sep 19, 2012 11:00 PM
NSTimer not firing eddjc Mac Programming 6 Jul 28, 2012 03:30 PM

Forum Jump

All times are GMT -5. The time now is 07:42 AM.

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

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