1
我想運行我的基於視圖的窗口應用程序與ticker.i有股票代碼,但它是在可可..所以我怎麼可以整合可可應用程序在我的項目。我怎樣才能整合iPhone應用程序中的代碼
這是TickerView.h文件
#import <Cocoa/Cocoa.h>
@interface TickerView : NSTextView {
@private
NSTimer *mTimer;
double mOffset;
}
- (NSString *)stringValue;
- (void)setStringValue:(NSString *)stringValue;
- (void)appendString:(NSString *)s;
- (IBAction)startAnimation:(id)sender;
- (IBAction)stopAnimation:(id)sender;
@end
這是TickerView.m文件
#import "TickerView.h"
@implementation TickerView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setEditable:NO];
NSTextContainer *container = [self textContainer];
[container setWidthTracksTextView:NO];
[container setContainerSize:NSMakeSize(99999., frame.size.height)];
}
return self;
}
- (void)dealloc {
[self stopAnimation:self];
[super dealloc];
}
- (void)drawRect:(NSRect)rect {
[super drawRect:rect];
}
- (NSString *)stringValue {
return [[self textStorage] string];
}
- (NSDictionary *)standardAttributes {
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Helvetica" size:([self frame].size.height * 0.8)], NSFontAttributeName,
[NSColor redColor], NSForegroundColorAttributeName,
nil];
}
- (void)setStringValue:(NSString *)s {
NSRange fullRange = NSMakeRange(0, [[self textStorage] length]);
NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease];
[[self textStorage] replaceCharactersInRange:fullRange withAttributedString:sa];
}
- (void)appendString:(NSString *)s {
NSRange endRange = NSMakeRange([[self textStorage] length], 0);
NSAttributedString *sa = [[[NSAttributedString alloc]initWithString:s attributes:[self standardAttributes]] autorelease];
[[self textStorage] replaceCharactersInRange:endRange withAttributedString:sa];
}
- (IBAction)startAnimation:(id)sender {
if (nil == mTimer) {
mTimer = [NSTimer scheduledTimerWithTimeInterval:1./60. target:self selector:@selector(step:) userInfo:nil repeats:YES];
}
}
- (IBAction)stopAnimation:(id)sender {
if (mTimer) {
[mTimer invalidate];
[mTimer release];
mTimer = nil;
}
}
- (void)step:(NSTimer *)timer {
mOffset -= 2; // pixels per tick
[self setTextContainerInset:NSMakeSize(mOffset, 0)];
[self setNeedsDisplay:YES];
}
@end
感謝您的suggetion .. 但它仍然無法正常工作。 – Pradeep 2010-07-08 14:07:28
需要更多的信息,而不是'不工作';) - 如果你編輯你的問題,你可以添加更多的細節。 – deanWombourne 2010-07-08 14:09:42
我做了我的代碼更改,因爲你說...但它仍然給我下面的錯誤..我是新的iPhone應用程序編程.. 'NSTextContainer'未申報(首次使用此功能) '容器'未申報在一次使用此功能) 「字體」未聲明(先入該函數使用) 「NSFontAttributeName」未聲明(在一次使用此功能) /「文字顏色」未聲明(在一次使用此功能) ' NSForegroundColorAttributeName'未申報(首次使用此功能) 請指導我 – Pradeep 2010-07-09 08:16:54