views:

56

answers:

1

Hi,

I am trying to create a contacts like app for iphone where the name of contact is displayed on the top (to do this I am writing code in viewForHeaderInSection) and then the details follows in the grouped section. The problem is I am retrieving the values from database and if the first name is null it is displayed on the table. I want to delete the null values and display the fields which has values in it. The names are saved in an array. I am trying to get the following fields from the database to display on the table.

NSMutableArray *nameSectionDetails=[[NSMutableArray alloc]initWithObjects:[eachContact objectAtIndex:0], [eachContact objectAtIndex:1], [eachContact objectAtIndex:2],[eachContact objectAtIndex:3],[eachContact objectAtIndex:4],[eachContact objectAtIndex:19],nil];

NSMutableDictionary *nameSection = [[NSMutableDictionary alloc]initWithObjectsAndKeys: nameSectionDetails, @"name", nil]; self.labelSection=nameSection;

eachContact has all the details of a particular contact.

This is where I am trying to display

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
 if(section == 0) {
  // create the parent view that will hold 1 or more buttons
  UIView* buttonView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 100.0)]autorelease];

  UILabel *updateDeletedLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 60.0)] autorelease];
  /*updateDeletedLabel.text = [NSString stringWithFormat:@"%@\n%@ %@\n%@\n%@",[eachContact objectAtIndex:1],[eachContact objectAtIndex:3],[eachContact objectAtIndex:2],[eachContact objectAtIndex:3],[eachContact objectAtIndex:4],[eachContact objectAtIndex:19]];*/
  /*for(int i=1;i<[[labelSection objectForKey:@"name"]count];i++)
  {
   if([[[labelSection objectForKey:@"name"]objectAtIndex:i] isEqualToString:@"(null)"])
    [[labelSection objectForKey:@"name"]removeObjectAtIndex:i];
   //i+=i*i;

  }*/


  updateDeletedLabel.text=[NSString stringWithFormat:@"%@ %@ %@\n%@\n%@\n%@",[[labelSection objectForKey:@"name"]objectAtIndex:1],[[labelSection objectForKey:@"name"]objectAtIndex:3],[[labelSection objectForKey:@"name"]objectAtIndex:5],[[labelSection objectForKey:@"name"]objectAtIndex:7],[[labelSection objectForKey:@"name"]objectAtIndex:9],[[labelSection objectForKey:@"name"]objectAtIndex:11]];

  updateDeletedLabel.font = [UIFont systemFontOfSize:12];
  updateDeletedLabel.numberOfLines = 0;
  updateDeletedLabel.lineBreakMode = UILineBreakModeWordWrap;
  updateDeletedLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
  [updateDeletedLabel setTextAlignment: UITextAlignmentCenter];

  // add the button to the parent view

  [buttonView addSubview:updateDeletedLabel];

  return buttonView;
 }
 return nil;
}

Can anyone please help me in this regard. I am a newbie learning iphone applications and if you can suggest any other method, I am glad to know that. Thanks!!!

+1  A: 

You should learn about customizing UITableCells

see http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#//apple_ref/doc/uid/TP40007451

especially this code: http://developer.apple.com/iphone/library/samplecode/TableViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007318

edit after clarification in comments

Still you should go the the mentioned documentation, as you are using the tableview wrong.

In the headerview for section 0 you would only return a view, that displays the photo and the name. (probably using a custom view loaded from a nib file)

the cells you would create in –tableView:cellForRowAtIndexPath:

edit

I was curious, what it does really take to do an app like that. Here are the results

THIS IS NOT READY FOR PRODUCTION — if name, familyname or pictureurl won't be provided, the DetailView will crash

          By using this code, you agree in doing your 
          homework and study the mentioned documentation!

screenshot

vikingosegundo
Thanks for the reply but this is not what I am looking for. For example if you tap on a contact in an indexed table view another view controller pops up which gives the details of that contact..I want it to look like the contacts application on iphone..please help..
racharambola
just for understanding: U have a tableview with n cells. in the cells u have the name. when u tab a cell, a view pops up, showing all the details. You are talking about that DetailView?
vikingosegundo
Yes you are right..I am talking about the detail view..I am sorry for all the confusion..can you please help?
racharambola
The detail view should be similar to the contacts on iphone
racharambola
Thanks a lot!!! I think this will help me out..I will check tomorrow and will let you know...once again thanx a ton..
racharambola
don't hesitate to vote up / accept my answer
vikingosegundo
sure I will do that..
racharambola
U haven't been on SO a long time, right? There are some arrows at the top left of any answer. If u find a answer useful, u click on the up-button. it only costs u a nano-second. It doesn't even have to be an answer to ur question. If u find an answer totally creepy, u done-vote it. But first u must have enough points to be able to do so. also it cost u 1 point of ur reputation. if it was ur answer u can additionally accept it. That will give u even 2 points. and the answerer 15. As up-votes doenst cost u anything, u shouuldnt be stingy with it.
vikingosegundo
Ya I tried it but it says we need to have atleast reputation of 15 but my reputation is only 5 :( sorry that's the only reason I couldn't do that..I will vote to the answer once I try it because I heard that once i vote it, this post will be not visible to anyone..please correct me if I am wrong..I am very thankful to you and I will definitely do that
racharambola
I just looked at ur questions. Actually some aren't uninteresting — but man: U must choose more descriptive and clearer titles and texts.
vikingosegundo
hey buddy somehow I got reputation of 15..so I voted for your answer..please check and thanks a lot..I will let you know if it works..
racharambola
haha I don't know..I think but eventually it helped you..I am happy :)..I am a newbie in iphone so I don't have clear idea of the concepts..can you please help me out if I have some queries..if so can you please give ur contact info..plzz
racharambola
SO is all the contact info u need. Just learn to use it wisely. I would consider myself to be a beginner in iPhone-development, too, as I just started more or less 6 month ago. But there is so much good documentation out there, it can be learned very fast. Just start at http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/GS_iPhoneGeneral/index.html and keep digging! obj-c is easy to learn, get familiar with MVC and delegate pattern. Then CoreData,....
vikingosegundo
Another hint: I learned a lot by watching the Stanford iPhone development course available in iTunes U: http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.3124430055
vikingosegundo