» Site Navigation |
|
|
» 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 |
|
 |
|
10-07-2008, 03:12 PM
|
#1 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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???
|
|
|
10-07-2008, 11:36 PM
|
#2 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
Try creating an NSMutableArray of NSMutableStrings. Add your random chars to each mutable string. It might make it easier to print it out.
|
|
|
10-08-2008, 10:00 AM
|
#3 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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
|
|
|
10-08-2008, 10:16 AM
|
#4 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
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.
|
|
|
10-08-2008, 10:39 AM
|
#5 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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???
|
|
|
10-08-2008, 12:21 PM
|
#6 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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)
|
|
|
10-08-2008, 01:53 PM
|
#7 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
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.
|
|
|
10-09-2008, 09:47 AM
|
#8 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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...
|
|
|
10-09-2008, 10:07 AM
|
#9 (permalink)
|
|
Senior Member
Join Date: Sep 2008
Posts: 682
|
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:@""];
}
|
|
|
10-10-2008, 07:36 AM
|
#10 (permalink)
|
|
Junior Member
Join Date: Oct 2008
Posts: 10
|
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....
|
|
|
 |
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|