Go Back   iPhone Dev SDK Forum > Development Forums > iPhone SDK Development

Featured Member Applications

TanZen ($0.99)

Endless Walls ($0.99)

Air Hockey ($0.99)

SUPER STRIKE - Motion Bowl ($0.99)

BarSlot ($0.99)

MeterRead ($0.99)

Colorblind Helper ($4.99)

gContacts ($1.99)

ProgCalc ($1.99)

Forex On The Go Lite (FREE)

HUE knewit! ($0.99)

Want your application to be advertised here?

» Advertisements


Visit our friends over at The App Show! Steve and Dave produce a weekly show shining a light on the iPhone 2.0 software and the applications being developed by the amazing development community for the iPhone SDK!
» Online Users: 96
13 members and 83 guests
blackyE, BSDimwit, bugnote, FetaBoy, hyang, logicpaw, mahr, Moose, pashik, RickMaddy, roberthuttinger, spinyanteater, uprise78
Most users ever online was 207, 10-24-2008 at 09:29 AM.
» Stats
Members: 3,915
Threads: 5,625
Posts: 23,285
Top Poster: scottiphone (705)
Welcome to our newest member, raysms
Reply
 
LinkBack Thread Tools Display Modes
Old 10-07-2008, 03:12 PM   #1 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default Writing in UIView

hi ppl,

I have this matrix:
Code:
        char **matrix;
	
	matrix = (char **) malloc(LINE * sizeof (char *));
	for(alloc=0; alloc < LINE; alloc++)
		matrix = (char **) malloc(COLUMN * sizeof (char *));
	
	for(i=0; i < LINE; i++)
		for(j=0; j < COLUMN; j++)
			matrix[i][j] =  'A' + + rand()%('Z' - 'A' + 1);
I think who I need print this matrix in a UIView for view in iPhone, but dont have success...

Any help or reference about this???
jumpi is offline   Reply With Quote
Old 10-07-2008, 11:36 PM   #2 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

Try creating an NSMutableArray of NSMutableStrings. Add your random chars to each mutable string. It might make it easier to print it out.
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 10:00 AM   #3 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default

Hi,

I make this:

Code:
- (char)randomStr {

	char temp;
	srand(time(NULL));
	temp = 'A' + rand()%('Z' - 'A' + 1);
	
	return temp;
	
}


	int i, j;
	NSMutableArray* row;
	
	NSMutableArray* matrix = [NSMutableArray new];
	for (i=0; i<LINE; i++){
		row = [NSMutableArray new];
		for(j=0; j < COLUMN; j++) 
			[row addObject: [NSString stringWithFormat:@"%c", [self randomStr]]]; 
		[matrix addObject: row];
	}
But I have problem... you have an example or reference for search this???

Thanks
jumpi is offline   Reply With Quote
Old 10-08-2008, 10:16 AM   #4 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

I don't know what you mean by 'search this' You need to explain better the problem you are having and the goal of this code.
PhoneyDeveloper is offline   Reply With Quote
Old 10-08-2008, 10:39 AM   #5 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default

I have progress...

I make this...

Code:
	srand(time(NULL));
	char matriz[LINE][COLUMN];
	
	NSString *teste;
	int i, j, px, py;
	
	//Preenchimento da matriz
	
	for(i=0; i < LINE; i++)
		for(j=0; j < COLUMN; j++) {
			
			matriz[i][j] =  'A' + + rand()%('Z' - 'A' + 1);
			teste = [NSString stringWithFormat:@"%c",matriz[i][j]];
		}
	
	CGPoint  location = CGPointMake(10, 20);
	UIFont   *font    = [UIFont systemFontOfSize:24];
	[[UIColor whiteColor] set];
	
	[teste drawAtPoint:location withFont:font];
But I dont print the matrix, I print the last char of teste, What print the matrix in screen???
jumpi is offline   Reply With Quote
Old 10-08-2008, 12:21 PM   #6 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default

Hi Phoney,

My intention is creating an word search puzzle app for my learning in iPhone development and I think who first step is show the matrix of chars in the screen.

Thanks for help and suggests are acceptable for this (documentation, examples)
jumpi is offline   Reply With Quote
Old 10-08-2008, 01:53 PM   #7 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

I think you need to build a single NSString for each row. That way when you draw the string it will draw the whole row. If you want to use the C 2D array as your data storage that is OK. Just build the string for drawing inside your drawRect: method.

Use NSMutableString appendFormat: and loop over the characters in one row adding them to the string. When you reach the end of the row then draw the string.

Another way would be to draw each character individually. Loop over the characters in each row and create a string for each character and then draw it. Or use NSMutableString setString: to replace the character.

You may want to use a fixed-width font like Courier.
PhoneyDeveloper is offline   Reply With Quote
Old 10-09-2008, 09:47 AM   #8 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default

Thanks for reply,

But I need of some example of this, any documentation, source....

have one form of creating a matrix in native Obj-C ? Any example, documentation of how to make this??? Thanks...
jumpi is offline   Reply With Quote
Old 10-09-2008, 10:07 AM   #9 (permalink)
Senior Member
 
Join Date: Sep 2008
Posts: 682
Default

No examples handy but something like this (untested) should print the values:

Code:
	NSMutableString*	s = [NSMutableString string];

	for (NSInteger i = 0; i < LINE; i++)
	{
		for (NSInteger j = 0; j < COLUMN; j++)
		{
			[s appendFormat:@" | %c |", matriz[i][j]];
		}
		location.y += 30.0f;	// move to new line
		[s drawAtPoint:location withFont:font];
		[s setString:@""];
	}
PhoneyDeveloper is offline   Reply With Quote
Old 10-10-2008, 07:36 AM   #10 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 10
Default

Thanks a lot Phoney!! I make some modifications and this work!!!

Hey, do you know any documentation about the use of selection in iPhone??? How to start with this???

Sorry for my inconvenience....
jumpi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Powered by vBadvanced CMPS v3.0.1

All times are GMT -5. The time now is 06:01 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0