Dealing with Core data one-to-many relationship - objective-c

I have been beating my head over this issue for some time now and my last hope is Stack Overflow.
Here is the app idea. I have two entities modeled in core data. The Golfer entity has a one to many relationship with FittingSession, so each golfer is capable of having more than one fitting session. I am not able to post an image for the data models as I am a new user.
But here are the details:
ENTITY: GOLFER and FITTING SESSION
Attributes for Golfer - first_name, last_name, emailId, contactNum, picture
Relationship : NSSet * fittingSessions
Attributes for Fitting Sessions - session_number, date, location, notes.
Relationship: Golfer * whoPlayed
I am working on one view controller called ViewManager (kinda base view for all my classes) and it has 2-3 Custom UIViews inside it. I animate them in and out whenever I need them.
I am getting my Golfers list-collection in a tableview from NSFetchedResultsController and getting the Fitting Sessions attributes in a tableview by the same technique using NSFetchedResultsController. My question is: How do I get a specific fitting session for a specific golfer? What do I have to write in TableViewDidSelectRow Method of Parent( Golfer )View? How do I deal with this one to many relationship? Here's my code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(tableView == mGolferTblView)
{
NSInteger count = [[self.fetchedResultsController sections] count];
NSLog(#"count section GOLFER TABLE VIEW=%d", count);
return count;
}
else if(tableView == mFittingTblView)
{
return 1;
}
else {
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == mGolferTblView)
{
id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSLog(#"count for array ROWS for GOLFERS =%d", [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
else if(tableView == mFittingTblView)
{
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"array here is=%#", mFittingSessionArray);
NSLog(#"count for ROWS in FITTING SESSIONS table view=%d", [mFittingSessionArray count]);
return [mFittingSessionArray count];
// id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fittingFetchedResultsController sections] objectAtIndex:section];
// NSLog(#"count for array ROWS for FITTING SESSIONS =%d", [sectionInfo numberOfObjects]);
// return [sectionInfo numberOfObjects];
}
else {
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger fullNameTag = 1;
static NSInteger imageTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *fakeLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 30, 100, 30)];
fakeLbl.backgroundColor = [UIColor clearColor];
fakeLbl.textColor = [UIColor grayColor];
fakeLbl.text=#"3 days ago";
[cell.contentView addSubview:fakeLbl];
[fakeLbl release];
UIImageView *btnImage =[[UIImageView alloc] initWithFrame:CGRectMake(250, 40, 25, 28)];
btnImage.image = [UIImage imageNamed:#"badge_25x28.png"];
btnImage.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:btnImage];
[btnImage release];
UILabel *fullNameLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 300, 30)];
fullNameLbl.backgroundColor = [UIColor clearColor];
fullNameLbl.textColor = [UIColor whiteColor];
fullNameLbl.numberOfLines = 1;
fullNameLbl.adjustsFontSizeToFitWidth = YES;
fullNameLbl.tag = fullNameTag;
[cell.contentView addSubview:fullNameLbl];
[fullNameLbl release];
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 71, 91)];
imageView.backgroundColor = [UIColor clearColor];
imageView.tag = imageTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
mGolfer = [self.fetchedResultsController objectAtIndexPath:indexPath];
UILabel * fullNameLbl = (UILabel *) [cell.contentView viewWithTag:fullNameTag];
fullNameLbl.text = mGolfer.fullName;
UIImageView * imgView = (UIImageView *) [cell.contentView viewWithTag:imageTag];
imgView.image = mGolfer.picture;
return cell;
}
if(tableView == mFittingTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger locationTag = 1;
static NSInteger notesTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UIImageView *iconImage =[[UIImageView alloc] initWithFrame:CGRectMake(10, 40, 11, 18)];
iconImage.image = [UIImage imageNamed:#"icon_locationmarker_11x18.png"];
iconImage.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:iconImage];
[iconImage release];
UILabel *fakeDateLbl =[[UILabel alloc] initWithFrame:CGRectMake(180, 15, 100, 20)];
fakeDateLbl.backgroundColor = [UIColor clearColor];
fakeDateLbl.textColor = [UIColor grayColor];
fakeDateLbl.text=#"apr.30.2012";
[cell.contentView addSubview:fakeDateLbl];
[fakeDateLbl release];
UIImageView *fakeImage1 =[[UIImageView alloc] initWithFrame:CGRectMake(25, 90, 43, 43)];
fakeImage1.image = [UIImage imageNamed:#"icon_catDriver_43x43.png"];
fakeImage1.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage1];
[fakeImage1 release];
UIImageView *fakeImage2 =[[UIImageView alloc] initWithFrame:CGRectMake(70, 90, 43, 43)];
fakeImage2.image = [UIImage imageNamed:#"icon_catFairway_43x43.png"];
fakeImage2.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage2];
[fakeImage2 release];
UIImageView *fakeImage3 =[[UIImageView alloc] initWithFrame:CGRectMake(115, 90, 43, 43)];
fakeImage3.image = [UIImage imageNamed:#"icon_catHybrid_43x43.png"];
fakeImage3.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage3];
[fakeImage3 release];
UIImageView *fakeImage4 =[[UIImageView alloc] initWithFrame:CGRectMake(160, 90, 43, 43)];
fakeImage4.image = [UIImage imageNamed:#"icon_catIron_43x43.png"];
fakeImage4.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage4];
[fakeImage4 release];
UIImageView *fakeImage5 =[[UIImageView alloc] initWithFrame:CGRectMake(205, 90, 43, 43)];
fakeImage5.image = [UIImage imageNamed:#"icon_catWedge_43x43.png"];
fakeImage5.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:fakeImage5];
[fakeImage5 release];
UILabel *sessionLbl =[[UILabel alloc] initWithFrame:CGRectMake(10, 7, 150, 30)];
sessionLbl.backgroundColor = [UIColor clearColor];
sessionLbl.textColor = [UIColor redColor];
sessionLbl.text = #"session";
sessionLbl.font = [UIFont boldSystemFontOfSize:18];
[cell.contentView addSubview:sessionLbl];
[sessionLbl release];
UILabel *locationLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 32, 270, 30)];
locationLbl.backgroundColor = [UIColor clearColor];
locationLbl.textColor = [UIColor whiteColor];
locationLbl.tag = locationTag;
[cell.contentView addSubview:locationLbl];
[locationLbl release];
UILabel *notesLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 54, 270, 30)];
notesLbl.backgroundColor = [UIColor clearColor];
notesLbl.textColor = [UIColor whiteColor];
notesLbl.tag = notesTag;
[cell.contentView addSubview:notesLbl];
[notesLbl release];
}
mFittingSessionArray = [mFittingSessionSet allObjects];
mFittingSession = [mFittingSessionArray objectAtIndex:indexPath.row];
UILabel *locationLbl = (UILabel *)[cell.contentView viewWithTag:locationTag];
locationLbl.text = mFittingSession.locationUppercase;
NSLog(#"location=%#", mFittingSession.locationUppercase);
UILabel *notesLbl = (UILabel *)[cell.contentView viewWithTag:notesTag];
notesLbl.text = mFittingSession.notesInQuotes;
return cell;
}
return 0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
mGolferNameLbl.text = mGolfer.fullName;
mGolferHeaderPicture.image = mGolfer.picture;
NSSet * fittingSessionSet = mGolfer.fittingSessions;
mFittingSessionArray = [fittingSessionSet allObjects];
NSLog(#"count for sessions=%d", [mFittingSessionArray count]);
NSLog(#"fiting sessions for golfer %# are= %#", mGolfer.first_name, mFittingSessionArray);
}
}
Also, this is how I add a new fitting session to a particular golfer:
- (IBAction)addNewSession:(id)sender
{
AppDelegate * applicationDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext * context = [applicationDelegate managedObjectContext];
mFittingSession=(FittingSession*) [NSEntityDescription insertNewObjectForEntityForName:#"FittingSession" inManagedObjectContext:context];
mFittingSession.location=mLocationTextField.text;
mFittingSession.notes=mNotesTxtView.text;
**mFittingSession.whoPlayed = self.golfer;** This is setting the relationship (whoPlayed is inverse relation to golfer provided by core data)
}
Please help me in this as I am really not getting how to deal with the relationship in core data. Please provide some code or snippets so that I can know what's going on.
Thank you

Maybe I don't understand your question correctly, but to get a Golfer's Fitting Session is really easy. So in the first code block you just do the following:
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
NSSet *fittingSession = mGolfer.fittingSessions;
You can access the relations as you would access the other attributes.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(tableView == mGolferTblView)
{
NSInteger count = [[self.fetchedResultsController sections] count];
NSLog(#"count section GOLFER TABLE VIEW=%d", count);
return count;
}
else if(tableView == mFittingTblView)
{
NSInteger countOfSections = 1;
NSLog(#"count section FITTING SESSION VIEW=%d", countOfSections);
return countOfSections;
}
else {
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == mGolferTblView)
{
id<NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSLog(#"count for ROWS in GOLFERS table view =%d", [sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
else if(tableView == mFittingTblView)
{
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"array here is=%#", mFittingSessionArray);
NSLog(#"count for ROWS in FITTING SESSIONS table view=%d", [mFittingSessionArray count]);
return [mFittingSessionArray count];
}
else {
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
static NSString *CellIdentifier = #"Cell";
static NSInteger fullNameTag = 1;
static NSInteger imageTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *fullNameLbl =[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 300, 30)];
fullNameLbl.backgroundColor = [UIColor clearColor];
fullNameLbl.textColor = [UIColor whiteColor];
fullNameLbl.numberOfLines = 1;
fullNameLbl.adjustsFontSizeToFitWidth = YES;
fullNameLbl.tag = fullNameTag;
[cell.contentView addSubview:fullNameLbl];
[fullNameLbl release];
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 71, 91)];
imageView.backgroundColor = [UIColor clearColor];
imageView.tag = imageTag;
[cell.contentView addSubview:imageView];
[imageView release];
}
mGolfer = [self.fetchedResultsController objectAtIndexPath:indexPath];
UILabel * fullNameLbl = (UILabel *) [cell.contentView viewWithTag:fullNameTag];
fullNameLbl.text = mGolfer.fullName;
UIImageView * imgView = (UIImageView *) [cell.contentView viewWithTag:imageTag];
imgView.image = mGolfer.picture;
return cell;
}
else if(tableView == mFittingTblView)
{
**mFittingSessionArray = [mFittingSessionSet allObjects];** // Added this line
static NSString *CellIdentifier = #"Cell";
static NSInteger locationTag = 1;
static NSInteger notesTag = 2;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel *locationLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 32, 270, 30)];
locationLbl.backgroundColor = [UIColor clearColor];
locationLbl.textColor = [UIColor whiteColor];
locationLbl.tag = locationTag;
[cell.contentView addSubview:locationLbl];
[locationLbl release];
UILabel *notesLbl =[[UILabel alloc] initWithFrame:CGRectMake(30, 54, 270, 30)];
notesLbl.backgroundColor = [UIColor clearColor];
notesLbl.textColor = [UIColor whiteColor];
notesLbl.tag = notesTag;
[cell.contentView addSubview:notesLbl];
[notesLbl release];
}
mFittingSession = [mFittingSessionArray objectAtIndex:indexPath.row];
UILabel *locationLbl = (UILabel *)[cell.contentView viewWithTag:locationTag];
UILabel *notesLbl = (UILabel *)[cell.contentView viewWithTag:notesTag];
locationLbl.text = mFittingSession.locationUppercase;
notesLbl.text = mFittingSession.notesInQuotes;
return cell;
}
else {
}
return 0;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == mGolferTblView)
{
if(self.editing)
{
[self.golferTblView deselectRowAtIndexPath:indexPath animated:YES];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^ {
mEditGolfersView.hidden = NO;
mEditGolfersView.frame = CGRectMake(305, mEditGolfersView.frame.origin.y, mEditGolfersView.frame.size.width, mEditGolfersView.frame.size.height);
}
completion:NULL];
mGolfer = (Golfer *) [self.fetchedResultsController objectAtIndexPath:indexPath];
mEditFirstName.text = mGolfer.first_name;
mEditMiddleName.text = mGolfer.middle_name;
mEditLastName.text = mGolfer.last_name;
mEditEmailField.text = mGolfer.email_id;
mEditContactNum.text = mGolfer.contactNumber;
mEditPictureView.image = mGolfer.picture;
mShowDataBtn.enabled = NO;
return;
}
[self.golferTblView deselectRowAtIndexPath:indexPath animated:YES];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut
animations:^ {
mGolfersView.frame = CGRectMake(-260, mGolfersView.frame.origin.y, mGolfersView.frame.size.width, mGolfersView.frame.size.height);
}
completion:^(BOOL finished){
mGolfersView.hidden = YES;
}];
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn
animations:^ {
mFittingSessionView.hidden = NO;
mFittingSessionView.frame = CGRectMake(-19, mFittingSessionView.frame.origin.y, mFittingSessionView.frame.size.width, mFittingSessionView.frame.size.height);
}
completion:NULL];
mGolfer = (Golfer *)[self.fetchedResultsController objectAtIndexPath:indexPath];
mGolferNameLbl.text = mGolfer.fullName;
mGolferHeaderPicture.image = mGolfer.picture;
mFittingSessionSet = mGolfer.fittingSessions;
mFittingSessionArray = [mFittingSessionSet allObjects];
NSLog(#"count for sessions=%d", [mFittingSessionArray count]);
NSLog(#"fiting sessions for golfer %# are= %#", mGolfer.first_name, mFittingSessionArray);
**[mFittingTblView reloadData];** // Added this and this reloads the data for fitting view.
}
}

Related

UITableView section not reloading when called

I want a section of my table view to reload whenever the ViewWillAppear method is called, I've implemented this like so:
- (void)viewWillAppear:(BOOL)animated {
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:0 inSection:1];
reloadRows = [NSArray arrayWithObjects:rowToReload, nil];
[self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
}
Here is the rowforsection method that indicates which content should appear in each tableview section:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"fadk");
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"PINGAS"];
[self.tableView setAlwaysBounceVertical:YES];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:#"PINGAS"] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
// if ([indexPath section] == 0) {
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 3, 300, 41)];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 0, 300, 120)];
UIView *paddingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 0)] autorelease];
paddingView.backgroundColor = [UIColor cyanColor];
// if ([indexPath row] == 0) {
if ([indexPath section] == 0) {
NSLog(#"0");
[cell addSubview:textField];
if ([indexPath row] == 0) {
textField.placeholder = #"Title";
}
else{
textField.placeholder = #"Location";
}
}
else if ([indexPath section] == 1) {
NSLog(#"1");
NSDateFormatter *formatter;
NSString *eSString1;
NSString *eEString2;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"h:mm a"];
cell.textLabel.text = #"Starts\nEnds";
cell.textLabel.numberOfLines = 2;
eSString1 = [formatter stringFromDate:eSTime];
eEString2 = [formatter stringFromDate:eEtime];
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#\n%#", eSString1, eEString2];
cell.detailTextLabel.numberOfLines = 2;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else{
NSLog(#"2");
[cell addSubview:textView];
}
textField.delegate = self;
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor blackColor];
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.tag = 0;
//playerTextField.delegate = self;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
[textField release];
textView.delegate = self;
textView.textColor = [UIColor blackColor];
textView.keyboardType = UIKeyboardTypeAlphabet;
textView.returnKeyType = UIReturnKeyDone;
textView.backgroundColor = [UIColor clearColor];
textView.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textView.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textView.textAlignment = UITextAlignmentLeft;
textView.tag = 0;
[textView release];
// }
}
return cell;
}
This works swimmingly the first load, and I after the first calling of viewWillAppear, but after that the section seems to recycle the data from the first load and the second load, and while it still enters the cellforrow section, it no longer goes into the section I call in the viewWIllAppear section.
The reload should be sandwiched between begin / end updates:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

populate data in iphone dynamically

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [self.LoadFile count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 4;
}
int title =0;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
for (title = 0 ; title <= section; title++)
{
NSLog(#"section - %d ",title);
NSDictionary *dict = [LoadFile objectAtIndex:title];
NSString *titlename = [[NSString alloc]initWithFormat:#"%#",[dict valueForKey:#"name"]];
NSLog(#"%#",titlename);
if (section == title)
return titlename;
}
}
Here i am using two arrays which is created on the page itself,in this case it will work fine but for the case when i need it to populate from DB then what should i do.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
while (i < sec)
{
dict = [LoadFile objectAtIndex:0];
NSString *addr = [[NSString alloc]initWithFormat:#"%#",[dict valueForKey:#"address"]];
NSString *con = [[NSString alloc]initWithFormat:#"%#",[dict valueForKey:#"contact"]];
NSString *sal = [[NSString alloc]initWithFormat:#"%#",[dict valueForKey:#"salary"]];
NSString *tec = [[NSString alloc]initWithFormat:#"%#",[dict valueForKey:#"tech"]];
NSArray *arr = [[NSArray alloc] initWithObjects:addr,con,sal,tec,nil];
// NSArray *arr = [[NSArray alloc] initWithObjects:i,i,i,i,nil];
//NSArray *arr2 = [[NSArray alloc] initWithObjects:#"12",#"22",#"32",#"42",nil];
NSLog(#"%#",arr);
if(indexPath.section == i)
{
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
i++;
}
}
return cell;
}
for (i = 0 ; i <= sec-1; i++)
{
NSLog(#"section - %d ",title);
NSDictionary *dict = [LoadFile objectAtIndex:title];
if (indexPath.section == 0)
{
UILabel *Address = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
Address.textColor = [UIColor blueColor];
Address.backgroundColor = [UIColor clearColor];
[Address setFont:[UIFont boldSystemFontOfSize:14.0]];
[Address setTag:i];
Address.text = [dict objectForKey:#"address"];
[cell.contentView addSubview:Address];
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
[tech setTag:i];
tech.text = [dict objectForKey:#"tech"];
[cell.contentView addSubview:tech];
}
else if (indexPath.section == 1)
{
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
[tech setTag:i];
tech.text = [dict objectForKey:#"tech"];
[cell.contentView addSubview:tech];
}
}
else if (indexPath.section == 0)
{
UILabel *contact = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
contact.textColor = [UIColor blueColor];
contact.backgroundColor = [UIColor clearColor];
[contact setFont:[UIFont boldSystemFontOfSize:14.0]];
contact.text = [dict objectForKey:#"contact"];
// NSLog(#"Val-%#",[dict objectForKey:#"name"]);
[contact setTag:-4];
[cell.contentView addSubview:contact];
}
else if (indexPath.section == 0)
{
UILabel *salary = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
salary.textColor = [UIColor blueColor];
salary.backgroundColor = [UIColor clearColor];
[salary setFont:[UIFont boldSystemFontOfSize:14.0]];
salary.text = [dict objectForKey:#"salary"];
// NSLog(#"Val-%#",[dict objectForKey:#"name"]);
[salary setTag:-4];
[cell.contentView addSubview:salary];
}
else
{
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
tech.text = [dict objectForKey:#"tech"];
// NSLog(#"Val-%#",[dict objectForKey:#"name"]);
[tech setTag:-4];
[cell.contentView addSubview:tech];
}
I want to populate data from table in database ,dynamically
Once your array has been updated with new data, you just call [self.tableview reloadData];

How to call numberOfRowsInSection and cellForRowAtIndexPath alternatively

I am working on an application in which data is displaying from back end to tableview.
The problem is, when table is loading, it gets all the data but displays only the last entry of database in each row. suppose last section has 3 rows then it displays only3 that 3 row data in each section.Even if in some section rows are 9 then the rest of rows are displaying blank.
I found it through break points that table first takes all the data from database and then read cellForRowAtIndexPath, As in my database last table has 3 rows, it displays the data of 3 rows only by keeping rest of rows blank.
Here is the coe of my numberOfRowsInSection and cellForRowAtIndexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if(requestType == 2)
{
if (self.uniqueCityCount > 0)
{
NSString *strCity = [self.arrayCityNames objectAtIndex:section]; //#"EventData" :#"EventCity"
NSPredicate *predicateSettings = [NSPredicate predicateWithFormat:#"(EventCity = %# )",strCity];
if ([self.arrayEventDescription count]>0)
{
[self.arrayEventDescription removeAllObjects];
}
self.arrayEventDescription = [CoreDataAPIMethods searchObjectsInContext:#"EventData" :predicateSettings :#"EventCity" :YES :self.managedObjectContext];
return [self.arrayEventDescription count];
}
/*
if (section == 0)
{
NSString *strCity = [self.arrayCityNames objectAtIndex:section]; //#"EventData" :#"EventCity"
NSPredicate *predicateSettings = [NSPredicate predicateWithFormat:#"(EventCity = %# )",strCity];
self.arrayEventDescription = [CoreDataAPIMethods searchObjectsInContext:#"EventData" :predicateSettings :#"EventCity" :YES :self.managedObjectContext];
return [self.arrayEventDescription count];
}
else if (section == 1)
{
}*/
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [#"" stringByAppendingFormat:#"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if(requestType == 2)
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// for (int j = 0 ; j < [self.arrayEventDescription count]; j++)
// for(int j=0; j<[tableView numberOfSections]; j++)
//{
NSLog(#"at section %d",indexPath.section);
NSLog(#"at row %d",indexPath.row);
NSLog(#"array count %d",[self.arrayEventDescription count]);
if (indexPath.row < [self.arrayEventDescription count])
{
EventData *data = [self.arrayEventDescription objectAtIndex:indexPath.row];
//EventData *data = [self.arrayEventDescription objectAtIndex:j];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
// UIView *viewDescription = [[UIView alloc]initWithFrame:CGRectMake(00, 00, 480, 35)];
////////////////////// Labels for description of city events from database ////////////////////////////
UILabel *lblEvent = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 150, 30)];
lblEvent.font = [UIFont systemFontOfSize:12];
lblEvent.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 150, 30)];
lblEventAtDate.font = [UIFont systemFontOfSize:12];
lblEventAtDate.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 15, 150, 30)];
lblEventAtSchool.font = [UIFont systemFontOfSize:12];
lblEventAtSchool.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblEvent];
[cell.contentView addSubview:lblEventAtDate];
[cell.contentView addSubview:lblEventAtSchool];
lblEvent.text = data.EventName;
// lblEventAtDate.text = data.EventDate;
lblEventAtSchool.text = data.EventPlace;
}
//}
}
}
// Configure the cell...
return cell;
}
As a first thing, I moved everything out of cell == nil block, as reuse may not happen. See if this solves your problem.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [#"" stringByAppendingFormat:#"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor clearColor];
if(requestType == 2)
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
// for (int j = 0 ; j < [self.arrayEventDescription count]; j++)
// for(int j=0; j<[tableView numberOfSections]; j++)
//{
NSLog(#"at section %d",indexPath.section);
NSLog(#"at row %d",indexPath.row);
NSLog(#"array count %d",[self.arrayEventDescription count]);
//}
}
if (indexPath.row < [self.arrayEventDescription count])
{
EventData *data = [self.arrayEventDescription objectAtIndex:indexPath.row];
//EventData *data = [self.arrayEventDescription objectAtIndex:j];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.backgroundColor=[UIColor clearColor];
// UIView *viewDescription = [[UIView alloc]initWithFrame:CGRectMake(00, 00, 480, 35)];
////////////////////// Labels for description of city events from database ////////////////////////////
UILabel *lblEvent = [[UILabel alloc]initWithFrame:CGRectMake(15, 00, 150, 30)];
lblEvent.font = [UIFont systemFontOfSize:12];
lblEvent.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtDate = [[UILabel alloc]initWithFrame:CGRectMake(200, 00, 150, 30)];
lblEventAtDate.font = [UIFont systemFontOfSize:12];
lblEventAtDate.backgroundColor = [UIColor clearColor];
UILabel *lblEventAtSchool = [[UILabel alloc]initWithFrame:CGRectMake(350, 15, 150, 30)];
lblEventAtSchool.font = [UIFont systemFontOfSize:12];
lblEventAtSchool.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblEvent];
[cell.contentView addSubview:lblEventAtDate];
[cell.contentView addSubview:lblEventAtSchool];
lblEvent.text = data.EventName;
// lblEventAtDate.text = data.EventDate;
lblEventAtSchool.text = data.EventPlace;
}
}
// Configure the cell...
return cell;
}
Can you tell me what is the request type and when it will be called(a set of possible values).
Quick Solution: You are checking the condition of request type first if(requestType == 2) { and then you are loading the cell. This delegate method will be called on loading the tableview, but requesttype is 2. So for indexpath.row=0 & 1, it wont go inside to load the cell and it loads only for requesttype=2. So it is loading third row.

how can i make a uitableview container to bounce within the view

ok, so this is pretty simple one, but i hope i could explain this clearly - i have a table view that i would like to inset into a container, and then have the table bounces when it reaches the top / bottom. So far, I was able to put my table in a container, but the container is fixed on the view, while the table inside the container bounces. Again, I am looking for a way to fix the table to the container, while having the container bouncing.
Here is what I was able to do, following the code:
What I want to accomplish is to have the black box bouncing rather than the table within it.
my ViewDidLoad in the view controller .m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//General View Setup
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"backgroundimage.png"]];
self.view.backgroundColor = background;
//Table View Data
listOfItems = [[NSMutableArray alloc] init];
NSArray *appleComputers = [NSArray arrayWithObjects:#"iPhone",#"iPod",#"MacBook",#"MacBook Pro",nil];
NSDictionary *appleComputersDict = [NSDictionary dictionaryWithObject:appleComputers forKey:#"Computers"];
NSArray *otherComputers = [NSArray arrayWithObjects:#"HP", #"Dell", #"Windows", #"Sony", #"Ivory", #"IBM", nil];
NSDictionary *otherComputersDict = [NSDictionary dictionaryWithObject:otherComputers forKey:#"Computers"];
[listOfItems addObject:appleComputersDict];
[listOfItems addObject:otherComputersDict];
self.navigationItem.title = #"Computers";
// Create a table
tblSimpleTable.delegate = self;
CGRect cgRct = CGRectMake(10, 50, 300, 300);
tblSimpleTable = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStyleGrouped]; // Initilize the table
[tblSimpleTable setBackgroundColor:[UIColor blackColor]];
tblSimpleTable.sectionHeaderHeight = 30.0;
tblSimpleTable.sectionFooterHeight = 30.0;
tblSimpleTable.delegate = self;
tblSimpleTable.dataSource = self;
[self.view addSubview:tblSimpleTable];
//Create the header
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)];
headerLabel.text = NSLocalizedString(#"Header for the table", #"");
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor yellowColor];
headerLabel.shadowOffset = CGSizeMake(0, 1);
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[containerView addSubview:headerLabel];
self.tblSimpleTable.tableHeaderView = containerView;
}
why don’t you use UIScrollView for that.
I had tested your code & done required changes. Hope you like it.
Code :
(this is your .h file)
#import <UIKit/UIKit.h>
#interface tableScrollViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource, UIScrollViewDelegate> {
UITableView *tblSimpleTable;
NSMutableArray *listOfItems;
NSMutableArray *appleComputers,*otherComputers;
UIScrollView *scrollView;
}
#end
(this is your .m file)
- (void)viewDidLoad {
[super viewDidLoad];
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 600)];
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor grayColor];
scrollView.contentSize = CGSizeMake(300, 800);
appleComputers = [[NSMutableArray alloc] init]; // I made it by my style
[appleComputers addObject: #"iPhone"];
[appleComputers addObject:#"iPod"];
[appleComputers addObject:#"MacBook"];
[appleComputers addObject:#"MacBook Pro"];
otherComputers = [[NSMutableArray alloc] init];
[otherComputers addObject: #"HP"];
[otherComputers addObject:#"Dell"];
[otherComputers addObject:#"Windows"];
[otherComputers addObject:#"Sony"];
[otherComputers addObject:#"Ivory"];
[otherComputers addObject:#"IBM"];
self.navigationItem.title = #"Computers";
// Create a table
tblSimpleTable.delegate = self;
CGRect cgRct = CGRectMake(10, 50, 300, 600);
tblSimpleTable = [[UITableView alloc] initWithFrame:cgRct
style:UITableViewStyleGrouped]; // Initilize the table
[tblSimpleTable setBackgroundColor:[UIColor blackColor]];
tblSimpleTable.sectionHeaderHeight = 30.0;
tblSimpleTable.sectionFooterHeight = 30.0;
tblSimpleTable.scrollEnabled = NO;
tblSimpleTable.delegate = self;
tblSimpleTable.dataSource = self;
[scrollView addSubview:tblSimpleTable];
self.view = scrollView;
//Create the header
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)];
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 300, 40)];
headerLabel.text = NSLocalizedString(#"Header for the table", #"");
headerLabel.textColor = [UIColor whiteColor];
headerLabel.shadowColor = [UIColor yellowColor];
headerLabel.shadowOffset = CGSizeMake(0, 1);
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[containerView addSubview:headerLabel];
tblSimpleTable.tableHeaderView = containerView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section == 0)
return [appleComputers count];
else if(section == 1)
return [otherComputers count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section == 0)
cell.text = [NSString stringWithFormat:#"%#“,
[appleComputers objectAtIndex:indexPath.row]];
else if(indexPath.section == 1)
cell.text = [NSString stringWithFormat:#"%#“,
[otherComputers objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
// do whatever here
}

Remove top shadow in my grouped UITableView?

I am a little OCD and this is driving me insane. I have been messing around with these settings for a long time.
I have a UITableView grouped that I have a shadow on the top. When you tap the top cell, it removes. What gives?
I've been stressing over this for the past hour or so. Is there a simple solution for this? Or am I just going insane?
Thanks,
Coulton
EDIT:
viewDidLoad:
formTableView.backgroundColor = [UIColor clearColor];
formTableView.layer.borderColor = [UIColor clearColor].CGColor;
formTableView.separatorColor = [UIColor colorWithRed:(194.0 / 255.0) green:(194.0 / 255.0) blue:(194.0 / 255.0) alpha: 1];
Here is how I display my cells. WARNING: It's a lot of code. There's a bunch of stuff in there you will have to sort through, so sort through it at your own risk! :)
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
// What to do when you click delete.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
//RootViewController.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return [formDataOne count];
} else {
return [formDataTwo count];
}
}
//RootViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
for (UIView *subview in [cell.contentView subviews]) {
[subview removeFromSuperview];
}
// Set up the cell...
NSString *cellValue;
if (indexPath.section == 0) {
cellValue = [formDataOne objectAtIndex:indexPath.row];
} else {
cellValue = [formDataTwo objectAtIndex:indexPath.row];
}
if (indexPath.section == 0) {
cell.text = #"";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row == 0) {
addTitle = [[UITextField alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
addTitle.borderStyle = UITextBorderStyleNone;
addTitle.textColor = [UIColor blackColor]; //text color
addTitle.font = [UIFont systemFontOfSize:16.0]; //font size
addTitle.placeholder = #"Album Name"; //place holder
addTitle.backgroundColor = [UIColor clearColor]; //background color
addTitle.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
addTitle.keyboardType = UIKeyboardTypeDefault; // type of the keyboard
addTitle.returnKeyType = UIReturnKeyDone; // type of the return key
addTitle.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
addTitle.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
[cell.contentView addSubview:addTitle];
} else if (indexPath.row == 1) {
// Set up loading text and show it
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
myLabel.text = #"Private Album";
myLabel.textColor = [UIColor blackColor];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.font = [UIFont fontWithName:#"Helvetica" size: 16.0];
myLabel.numberOfLines = 0;
//[myLabel sizeToFit];
privateSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[privateSwitch addTarget:self action:#selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside];
[cell.contentView addSubview:privateSwitch];
//[privateSwitch setOn:NO animated:NO];
if ([howToDisplay isEqualToString:#"no"]) {
[privateSwitch setOn:NO animated:NO];
} else {
[privateSwitch setOn:YES animated:NO];
}
[cell.contentView addSubview:myLabel];
} else {
// Set up loading text and show it
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)];
myLabel.text = #"Comments";
myLabel.textColor = [UIColor blackColor];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.backgroundColor = [UIColor clearColor];
myLabel.font = [UIFont fontWithName:#"Helvetica" size: 16.0];
myLabel.numberOfLines = 0;
//[myLabel sizeToFit];
[cell.contentView addSubview:myLabel];
commentsSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:commentsSwitch];
[commentsSwitch setOn:YES animated:NO];
}
} else {
//cell.text = cellValue;
UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake(48, 12, 130, 20)];
labelOne.text = cellValue;
labelOne.textColor = [UIColor blackColor];
[labelOne setFont:[UIFont boldSystemFontOfSize:16]];
labelOne.textAlignment = UITextAlignmentLeft;
labelOne.backgroundColor = [UIColor clearColor];
//labelOne.font = [UIFont fontWithName:#"Helvetica"];
labelOne.numberOfLines = 0;
[cell.contentView addSubview:labelOne];
if (indexPath.row == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else if (indexPath.row == 1) {
int countFacebook = [dataCeter.connectionFacebookArray count];
if (countFacebook == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
} else if (indexPath.row == 2) {
//} else if (indexPath.row == 3) {
} else if (indexPath.row == 3) {
int countTumblr = [dataCeter.connectionTumblrArray count];
if (countTumblr == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
} else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
} else if (indexPath.row == 4) {
} else if (indexPath.row == 5) {
} else {
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
}
// Set imageView with correct thumbnail
UIImage *theImage;
if ([cellValue isEqualToString:#"Facebook"]) {
theImage = [UIImage imageNamed:#"icon_small_facebook.png"];
int countFacebook = [dataCeter.connectionFacebookArray count];
NSLog(#"facebook? %d // %#", countFacebook, dataCeter.connectionFacebookArray);
if (countFacebook != 0) {
facebookSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:facebookSwitch];
[facebookSwitch setOn:YES animated:NO];
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
} else if ([cellValue isEqualToString:#"Twitter"]) {
theImage = [UIImage imageNamed:#"icon_small_twitter.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if ([cellValue isEqualToString:#"Flickr"]) {
theImage = [UIImage imageNamed:#"icon_small_flickr.png"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else if ([cellValue isEqualToString:#"Tumblr"]) {
theImage = [UIImage imageNamed:#"icon_small_tumblr.png"];
int countTumblr = [dataCeter.connectionTumblrArray count];
if (countTumblr != 0) {
tumblrSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:tumblrSwitch];
[tumblrSwitch setOn:YES animated:NO];
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
} else if ([cellValue isEqualToString:#"Email"]) {
theImage = [UIImage imageNamed:#"icon_small_email.png"];
int countEmail = [dataCeter.connectionEmailArray count];
} else if ([cellValue isEqualToString:#"MMS"]) {
theImage = [UIImage imageNamed:#"icon_small_mms.png"];
int countMMS = [dataCeter.connectionSMSArray count];
} else if ([cellValue isEqualToString:#"Photostream"]) {
theImage = [UIImage imageNamed:#"icon_small_photostream.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
photostreamSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[cell.contentView addSubview:photostreamSwitch];
[photostreamSwitch setOn:YES animated:NO];
} else {
theImage = nil;
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.imageView.image = theImage;
return cell;
}
Set your table view's separator style to UITableViewCellSeparatorStyleSingleLine. It's currently being set to UITableViewCellSeparatorStyleSingleLineEtched, which gives the effect of a doubled top border on the iPhone (it looks more detailed on iOS 5, and on iOS 3.2 and 4 on the iPad).
You're not insane, it looks like there is an extra pixel in there.
Try taking out "Sharing" and see if it still happens. Curious to see if the shadow is on "Sharing" or the table itself.
If that's the case, then you know your header view has a problem, not the table view.