Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 08-11-2011, 08:55 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 7
pleasehelp is on a distinguished road
Default ASIHTTP - tableView - CSV

Hello guys,

firstable i want to say is that i´m new here and the forum is the best place i have seen for iphone development.

My configuration: Tab Bar with tableView -> klick on row -> detailview

My problem: i make a request with asihttp. so far so good. i get a response

like:
name;tel;email

Hans Mustermann;0123/45678;info@yourdomain.com
Harry the second;98765/12345;my@email.com

in moment i handle the response like:

NSArray *cusNameDataArray = nil;
cusNameDataArray = [[response componentsSeparatedByString:@"\n"]retain];
self.cusNameDataArray =[[NSMutableArray alloc] initWithArray:cusNameDataArray];
[cusNameDataArray release];

and in:

-(UITableViewCell *)tableViewUITableView *)cusTableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *identifier = @"Cell";

UITableViewCell *cell = [self.cusTableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];


// Set up the cell...
cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:12];
cell.textLabel.text = here i want the name
cell.detailTextLabel.font = [UIFont fontWithName:@"Verdana" size:10];
cell.detailTextLabel.text = here i want the email and tel;

return cell;
}

you can see that i just want the name in cell.textLabel.text and in cell.detailTextLabel.text the email and telefon

can somebody help me an give me an example? i waste so much time for this solution but nothing found.
pleasehelp is offline   Reply With Quote
Old 08-11-2011, 02:22 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 241
MattW is on a distinguished road
Default

Quote:
Originally Posted by pleasehelp View Post
Hello guys,

firstable i want to say is that i´m new here and the forum is the best place i have seen for iphone development.

My configuration: Tab Bar with tableView -> klick on row -> detailview

My problem: i make a request with asihttp. so far so good. i get a response

like:
name;tel;email

Hans Mustermann;0123/45678;info@yourdomain.com
Harry the second;98765/12345;my@email.com

in moment i handle the response like:

NSArray *cusNameDataArray = nil;
cusNameDataArray = [[response componentsSeparatedByString:@"\n"]retain];
self.cusNameDataArray =[[NSMutableArray alloc] initWithArray:cusNameDataArray];
[cusNameDataArray release];

and in:

-(UITableViewCell *)tableViewUITableView *)cusTableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *identifier = @"Cell";

UITableViewCell *cell = [self.cusTableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];


// Set up the cell...
cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:12];
cell.textLabel.text = here i want the name
cell.detailTextLabel.font = [UIFont fontWithName:@"Verdana" size:10];
cell.detailTextLabel.text = here i want the email and tel;

return cell;
}

you can see that i just want the name in cell.textLabel.text and in cell.detailTextLabel.text the email and telefon

can somebody help me an give me an example? i waste so much time for this solution but nothing found.
One option would be to do further parsing of your curNameDataArray. After your call to componentsSeparatedByString, your array contains one entry per line of the response.

You could then iterate through every string in that array, and separate the string into further strings by separating based on ';'. This would break the string into an array containing 3 entries - the name, phone number, and e-mail address.

Alloc your curNameDataArray and add each broken up array to it, so you'll end up with an array of arrays. The code would look something like:

Code:
// Build an array of each individual line
NSArray *tempArray = [response componentsSeparatedByString:@"\n"];
// Allocate my customer array
self.cusNameDataArray =[[NSMutableArray alloc] init];

// Iterate over ever line and break it up into its components
for (int i=0; i<[tempArray count]; i++)
{
  NSString *line = [tempArray objectAtIndex:i];
  NSArray *cusComponents = [line componentsSeparatedByString:@";"];

  // cusComponents now contains 3 entries - name, number, e-mail. Add this to your customer data array
  [self.cusNameDataArray addObject:cusComponents];
}
And now you have an array of customers. Each customer entry is an array of the 3 pieces of information. To get at it:

Code:
NSArray *customerData = [self.cusNameDataArray objectAtIndex:<customer number>];

NSString *customerName = [customerData objectAtIndex:0];
NSString *customerPhone = [customerData objectAtIndex:1];
NSString *customerEmail = [customerData objectAtIndex:2];
Is that the sort of thing you were after?


(One other thing to note: Having a variable declared in your class that is exactly the same as a local variable defined in a function is not ideal - it's easy to get confused as to which is being written to or read from, and silly bugs can easily crop up.)
__________________

Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)
-----
Create iPhone lists with no typing: Insta-List
-----
Make spelling fun, and create your own tests: iWillSpell
-----
A fast, elegant flashlight app: Insta-Light
-----


FourSixteen Productions
MattW is offline   Reply With Quote
Old 08-12-2011, 04:47 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 7
pleasehelp is on a distinguished road
Default

thanx for quick response!

i used your code but nothing happens.

the cells of tableview are empty -> cell.textlabel.text and cell.detailtextlabel.text

did i make a silly mistake?

- (void)viewDidLoad
{
[super viewDidLoad];

self.title = NSLocalizedString(@"Customers", @"My Customers");

NSURL *url = [NSURL URLWithString:@"http://www.yourdomain.com/some.php?do=yes"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
NSString *response = [request responseString];
NSLog(@"%@", response);

NSArray *cusDataArray = nil;
cusDataArray = [[response componentsSeparatedByString:@"\n"]retain];

// Allocate my customer array
self.cusDataArray =[[NSMutableArray alloc] init];

for (int i=0; i<[cusTempArray count]; i++)
{
NSString *cusLine = [cusTempArray objectAtIndex:i];
NSArray *cusComponents = [cusLine componentsSeparatedByString:@";"];

// cusComponents now contains 3 entries - name, number, e-mail. Add this to your customer data array
[self.cusDataArray addObject:cusComponents];
}

}

[cusDataArray release];
}

-------


-(UITableViewCell *)tableView:(UITableView *)cusTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *identifier = @"Cell";

UITableViewCell *cell = [self.cusTableView dequeueReusableCellWithIdentifier:identifier];
if(cell == nil)
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];

// Iterate over ever line and break it up into its components
for (int i=0; i<[cusTempArray count]; i++)
{
NSString *cusLine = [cusTempArray objectAtIndex:i];
NSArray *cusComponents = [cusLine componentsSeparatedByString:@";"];

// cusComponents now contains 3 entries - name, number, e-mail. Add this to your customer data array
[self.cusDataArray addObject:cusComponents];
}

//Set up the cell...
cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:12];
NSArray *customerData = [self.cusDataArray objectAtIndex:0];
NSString *customerName = [customerData objectAtIndex:0];
NSString *customerPhone = [customerData objectAtIndex:1];
cell.textLabel.text = customerName;
cell.detailTextLabel.font = [UIFont fontWithName:@"Verdana" size:10];
cell.detailTextLabel.text = [self.cusDataArray objectAtIndex:1];

return cell;
}
pleasehelp is offline   Reply With Quote
Reply

Bookmarks

Tags
asihttp, cell, request, semicolon, tableview

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



» Advertisements
» Online Users: 398
13 members and 385 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, dre, fiftysixty, gmarro, jimmyon122, jonathandeknudt, pungs, raymng, tymex, UMAD
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0