Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
Stockholm
Hello,

I am totally new and are trying to learn how to create iPhone apps.

When learning how to update the screen, I am trying to move a NSString around, but it multiplies and is positioned in different places. Can anyone tell me what I am not understanding? I am also an old Java guy, perhaps I am not understanding the language correctly...

Please see code below.

Thanks in advance!

Cheers,
Niklas
Code:
//
//  MyView.m
//  HelloWorld
//
//  Created by nic on 2009-10-13.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "MyView.h"
#import "TextClass.h"


@implementation MyView


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		location = CGPointMake(40, 20);
		id textObject = [[TextClass alloc] init];
		font = [UIFont systemFontOfSize:24];
		hello = [textObject getText];
		hello = [textObject getText];
    }
	
    return self;
}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
	location = point;
	[self setNeedsDisplay];
	return self;
	
}

- (void)drawRect:(CGRect)rect {
	
	CGPoint location2 = CGPointMake(10, 40);
	[[UIColor whiteColor] set];
	[hello drawAtPoint:location withFont:font];
	NSString *l = [NSString stringWithFormat:@"%d", [hello length]];
	[l drawAtPoint:location2 withFont:font];
	
	 }


- (void)dealloc {
    [super dealloc];
}


@end
Code:
//
//  MyView.h
//  HelloWorld
//
//  Created by nic on 2009-10-13.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

CGPoint location;
NSString *hello;
UIFont *font;


@interface MyView : UIView {

}

@end
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
If you need the entire view cleared/initialised to a solid colour you have to do it: setNeedsDisplay: just tells the OS that you need to update the view.
 

Nicsoft

macrumors member
Original poster
Oct 17, 2009
53
0
Stockholm
Hello, Thanks for your quick answer!

Ok I see. I tried to brows around finding out how to do this. Couldn't find any really good info. Is the strategy to use setNeedsDisplayRect and define the entire screen? I couldn't find any helpfull method for the UIView class. Or should I create a new instance of MyView?

Thanks again!

/Niklas
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.