- (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];
Related
I have a UIImageView installed on my cell, it is transparent black, but when I scroll the CollectionView and I raise my UIImageView but there is always more to transprence.
See picture :
1 - I is not even scroll
2 - After a scroll
My code :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"pictureCell";
MSContestListCollectionViewCell *cell = (MSContestListCollectionViewCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.titleContest.adjustsFontSizeToFitWidth = YES;
cell.titleContest.minimumScaleFactor = 0.5;
cell.pictureImageView.layer.cornerRadius = 5;
cell.pictureImageView.clipsToBounds = YES;
cell.titleView.layer.cornerRadius = 5;
cell.titleView.clipsToBounds = YES;
switch (_segmentedControl.selectedSegmentIndex) {
case 0: {
NSDictionary *searchResult = [self.readArray objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult objectForKey:#"featuredImage"];
NSString *image = [NSString stringWithFormat:#"https://srv.mediaswapp.com/%#", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
cell.statusContest.text = [searchResult objectForKey:#"status"];
if ([[searchResult objectForKey:#"status"] isEqualToString:#"PAUSE"]) {
cell.titleContest.text = [NSString stringWithFormat:#"Concours en pause"];
/*
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(cell.contentView.frame.origin.x, cell.contentView.frame.origin.y, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
view.layer.cornerRadius = 5;
view.clipsToBounds = YES;
[cell.contentView addSubview:view];
*/
UIImageView *imagecellPause = [[UIImageView alloc] initWithFrame:CGRectMake(cell.contentView.frame.origin.x, cell.contentView.frame.origin.y, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
UIImage *cellImage = [UIImage imageNamed:#"cell-pause.png"];
imagecellPause.image = cellImage;
[cell.contentView addSubview:imagecellPause];
UIImageView *imagePause = [[UIImageView alloc] initWithFrame:CGRectMake(69.5, 69.5, 25, 25)];
UIImage *image = [UIImage imageNamed:#"Pause Filled-50 (1).png"];
imagePause.image = image;
[cell.contentView addSubview:imagePause];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 90, 150, 50)];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:#"Avenir-Book" size:12];
label.text = [searchResult objectForKey:#"description"];
label.adjustsFontSizeToFitWidth = YES;
label.minimumScaleFactor = 0.5;
[cell.contentView addSubview:label];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 105, 150, 50)];
label2.textColor = [UIColor whiteColor];
label2.font = [UIFont fontWithName:#"Avenir-Black" size:15];
label2.text = #"Concours en pause";
[cell.contentView addSubview:label2];
cell.titleView.hidden = YES;
} else {
cell.titleContest.text = [searchResult objectForKey:#"description"];
}
break;
}
case 1: {
NSDictionary *searchResult2 = [self.readArrayWinner objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult2 objectForKey:#"featuredImage"];
NSString *image = [NSString stringWithFormat:#"https://srv.mediaswapp.com/%#", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
cell.titleContest.text = [searchResult2 objectForKey:#"description"];
cell.statusContest.text = [searchResult2 objectForKey:#"status"];
NSLog(#"le gagnant : %#", [searchResult2 valueForKeyPath:#"winners.name"]);
break;
}
case 2: {
NSDictionary *searchResult3 = [self.readArrayPhotos objectAtIndex:indexPath.item];
NSString *stringImage = [searchResult3 objectForKey:#"featuredImage"];
NSString *image = [NSString stringWithFormat:#"https://srv.mediaswapp.com/%#", stringImage];
[cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:image]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
cell.titleContest.text = [searchResult3 objectForKey:#"description"];
cell.statusContest.text = [searchResult3 objectForKey:#"status"];
break;
}
default:
break;
}
[_activity stopAnimating];
_label1.hidden = YES;
return cell;
}
Your CellForRowAtIndexPath should never contain addSubView, since everytime the cell is reloaded it will add the view. Thats why it keeps getting darker, it just adds view onto view.
Instead you should subclass your UICollectionViewCell and add the view in the subclass.
(
{
"first_name" = Akash;
idprofile = 1;
iduser = 1;
"last_name" = Testing;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/1_Jellyfish.jpg";
"profile_picture_filepath" = "1_Jellyfish.jpg";
},
{
"first_name" = testing;
idprofile = 3;
iduser = 1;
"last_name" = tst;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/3_Penguins.jpg";
"profile_picture_filepath" = "3_Penguins.jpg";
},
{
"first_name" = test;
idprofile = 4;
iduser = 1;
"last_name" = test;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/4_Chrysanthemum.jpg";
"profile_picture_filepath" = "4_Chrysanthemum.jpg";
},
{
"first_name" = prashant1;
idprofile = 19;
iduser = 1;
"last_name" = kharade1;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/19_Koala.jpg";
"profile_picture_filepath" = "19_Koala.jpg";
},
{
"first_name" = Priyank;
idprofile = 68;
iduser = 1;
"last_name" = Jain;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/68_P.jpg";
"profile_picture_filepath" = "68_P.jpg";
},
{
"first_name" = sdasd;
idprofile = 106;
iduser = 1;
"last_name" = sdasd;
picUrl = "http://qalina.acapglobal.com/kangatime/ktapp/profilepics/1/";
"profile_picture_filepath" = "<null>";
}
)
this is my json response data. I want to display the six profiles(6 dictionaries) based on the "idprofile" key in a table view with first_name, last_name and the profile image. I am getting confused. Please help?
here's my code:
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDel = [[UIApplication sharedApplication]delegate];
navBar=[[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[navBar setTintColor:[UIColor colorWithRed:0.0f/255.0f green:82.0f/255.0f blue:151.0f/255.0f alpha:1.0f]];
UIImageView *myImageView=[[UIImageView alloc] initWithFrame:CGRectMake(87, 3, 134, 33)];
myImageView.image=[UIImage imageNamed:#"sprofile.png"];
[navBar addSubview:myImageView];
//[myImageView release];
[self.view addSubview:navBar];
UIButton *logOutButton=[UIButton buttonWithType:UIButtonTypeCustom] ;
[logOutButton setFrame:CGRectMake(244, 10, 71, 32)];
//[logOutButton setTitle:#"Log out" forState:UIControlStateNormal];
[logOutButton setImage:[UIImage imageNamed:#"logout.png"] forState:UIControlStateNormal];
[logOutButton addTarget:self action:#selector(goToLoginScreen) forControlEvents:UIControlEventTouchUpInside];
[navBar addSubview:logOutButton];
UILabel *headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 320, 30)];
[headerLabel setBackgroundColor:[UIColor colorWithRed:210.0f/255.0f green:221.0f/255.0f blue:228.0f/255.0f alpha:1.0f]];
[headerLabel setText:#"Currently selected profile: Please select"];
[headerLabel setTextAlignment:NSTextAlignmentCenter];
[headerLabel setFont:[UIFont fontWithName:#"helvetica" size:14.0f]];
[headerLabel setTextColor:[UIColor colorWithRed:78.0f/255.0f green:126.0f/255.0f blue:70.0f/255.0f alpha:1.0f]];
[self.view addSubview:headerLabel];
homeTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 81, 320, 367) style:UITableViewStylePlain];
[homeTable setBackgroundColor:[UIColor colorWithRed:232.0f/255.0f green:237.0f/255.0f blue:240.0f/255.0f alpha:1.0f]];
homeTable.delegate=self;
homeTable.dataSource=self;
homeTable.rowHeight=100;
[self.view addSubview:homeTable];
profileArray = [[NSMutableArray alloc]init];
[self callWebService];
}
-(void)goToLoginScreen
{
AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [profileArray count];
}
- (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];
}
UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
selectButton.frame = CGRectMake(100, 30, 63, 32);
//[selectButton setBackgroundColor:[UIColor yellowColor]];
[selectButton setBackgroundImage:[UIImage imageNamed:#"select.png"] forState:UIControlStateNormal];
//[selectButton addTarget:self action:#selector(selectButtonSelected: ) forControlEvents:UIControlEventTouchUpInside];
selectButton.tag = indexPath.row;
[cell.contentView addSubview:selectButton];
// NSDictionary *item = [profileArray objectAtIndex:[indexPath row]];
// [[cell textLabel] setText:[item objectForKey:#"first_name"]];
// Home *tempHomeObj=(Home *)[profileArray objectAtIndex:indexPath.row];
// NSString *fName = (NSString *)tempHomeObj.fName;
// NSLog(#"fnameeeee==>%#",fName);
//NSLog(#"fName==>%#",appDel.fName);
AppDelegate *appDel=(AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(#"profileeeee==>%#",profileArray);
// NSMutableString *tempStr = (NSMutableString *)profileArray;
cell.textLabel.text = [self.profileArray objectAtIndex:indexPath.row];
//cell.imageView.image = appDel.tempUserImage;
return cell;
}
-(void)callWebService
{
//adding the indicator view to show that data is being processed.......
indicatorView=[[UIView alloc] initWithFrame:CGRectMake(110 ,180,100 , 100)];
indicatorView.tag=3000;
[indicatorView setAlpha:0.7];
indicatorView.layer.cornerRadius=15;
indicatorView.backgroundColor=[UIColor blackColor];
[self.view addSubview:indicatorView];
//now adding the activity indicator
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//activityIndicator.frame = CGRectMake(20.0,20.0, 40.0, 40.0);
//activityIndicator.center = indicatorView.center;
activityIndicator.center=CGPointMake(50, 50);
[activityIndicator startAnimating];
[[self.view viewWithTag:3000]addSubview:activityIndicator];
// AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSURL *url = [NSURL URLWithString:#"http://qalina.acapglobal.com/kangatime/kangatime_api/api/user/all_profiles/format/json"];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
[request addPostValue:#"1" forKey:#"id"];
//[request addPostValue:pwdField.text forKey:#"pass"];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// NSLog(#"responsestring==%#",responseString);
NSMutableArray *responseArr= [responseString JSONValue];
NSLog(#"responseArr==>%#",responseArr);
NSDictionary *tempDict = [responseArr objectAtIndex:0];
//NSLog(#"tempDict==>%#",tempDict);
if(indicatorView!=nil)
{
[indicatorView removeFromSuperview];
indicatorView=nil;
}
for(NSDictionary *dict in tempDict)
{
Home *objHome=[[Home alloc] init];
AppDelegate *appDel = [[UIApplication sharedApplication]delegate];
appDel.fName = [tempDict objectForKey:#"first_name"];
NSLog(#"appDel.fName==>%#",appDel.fName );
appDel.lName = [tempDict objectForKey:#"last_name"];
//NSLog(#"lName==>%#",lName);
NSMutableString *myStr=[NSMutableString stringWithString:appDel.fName];
[myStr appendFormat:#" "];
[myStr appendString:appDel.lName];
objHome.userName=myStr;
NSLog(#"objHome.userName==>%#",objHome.userName);
NSString *idProfile = [tempDict objectForKey:#"idprofile"];
NSLog(#"idProfile==>%#",idProfile);
// NSString *imageStr=[tempDict objectForKey:#"profile_picture_filepath"];
// NSMutableString *urlString= [NSMutableString stringWithString:#"http://qalina.acapglobal.com/kangatime/ktapp/profilepics/"];
// [urlString appendString:imageStr];
// NSURL *mainURL=[[[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]] autorelease];
// // NSLog(#"mainURL==>%#",mainURL);
//
// appDel.tempUserData = [[NSData alloc] initWithContentsOfURL:mainURL];
//NSLog(#"tempUserData==>%#",tempUserData);
// Home *objHome=[[Home alloc] init];
//appDel.tempUserImage = [[UIImage alloc] initWithData:appDel.tempUserData];
[profileArray addObject:objHome.userName];
// [profileArray addObject:appDel.tempUserImage];
NSLog(#"profileArray==>%d",[profileArray count]);
}
//[profileArray addObject:]
// [homeTable setDataSource:self];
// [homeTable setDelegate:self];
[homeTable reloadData];
//[self setProfileArray:[tempDict objectForKey:#"first_name"]];
}
first you have parse the json. to parse the jason you can use JSONKit
With the help of JSONKIT, first you have to parse response string.
You will get array or dictionary from JSON response. #SmartWork has provided you a link for JSONKIT and How to create JSON Array string given below? will help you out to retrieve array/dictionary from response.
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.
}
}
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.
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.