How to change image on button pressed with cell reused - ios

There is a problem. I need at the touch of a button to add to the array and at the button to change the image.
I do it this way:
- (IBAction)addUserAction:(UIButton *)sender {
CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *clickedButtonIndexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
NSInteger row = clickedButtonIndexPath.row;
UserCell* selectedCell = [self.tableView cellForRowAtIndexPath:clickedButtonIndexPath];
NSString* login = selectedCell.loginLabel.text;
BOOL userIsExist = selectedCell.isExist;
for (QBUUser* user in self.users) {
if ([login isEqualToString:user.login]) {
if (!userIsExist) {
[self.assistant.usersInCurrentChat addObject:user];
userIsExist = YES;
UIButton* button = self.buttons[clickedButtonIndexPath.row];
[button setImage:[UIImage imageNamed:#"delete_icon_64x64.png"] forState:UIControlStateNormal];
self.buttons[clickedButtonIndexPath.row] = button;
} else{
[self.assistant.usersInCurrentChat removeObject:user];
userIsExist = NO;
UIButton* button = self.buttons[clickedButtonIndexPath.row];
[button setImage:[UIImage imageNamed:#"add_button_64x64.png"] forState:UIControlStateNormal];
self.buttons[clickedButtonIndexPath.row] = button;
}
}
}
selectedCell.isExist = userIsExist;
}
my Code for cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UserCell* cell = [tableView dequeueReusableCellWithIdentifier:#"userCell1"];
if(!cell){
cell = [[UserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"userCell1"];
}
QBUUser* user = [self.users objectAtIndex:indexPath.row];
cell.loginLabel.text = [NSString stringWithFormat:#"%#", user.login];
NSInteger currentTimeInterval = [[NSDate date] timeIntervalSince1970];
NSInteger userLastRequestAtTimeInterval = [[user lastRequestAt] timeIntervalSince1970];
// if user didn't do anything last 1 minute (60 seconds)
if((currentTimeInterval - userLastRequestAtTimeInterval) > 60){
cell.statusImageView.image = [UIImage imageNamed:#"offline_icon_45x45.png"];
} else{
cell.statusImageView.image = [UIImage imageNamed:#"online_icon_32x32.png"];
}
NSInteger row = indexPath.row;
if ([self.buttons[indexPath.row] isEqual:[NSNull null]]) {
self.buttons[indexPath.row] = cell.button;
} else {
cell.button = self.buttons[indexPath.row];
}
return cell;
}
But the cell "reused" and I get the result as in the picture my bug
How do I fix this ?

Related

UItableview scrollsToTop is not working when click on button ios

I am having uicollection scrolling in horizontal direction , inside the collection view cell i have two table view - one _tablewView
-another _tblnoti , i have added a button for collapsing the order card , on click of that i want to scroll _tableView to the top , but its not working
on click of drop downbutton i m reloading the table view inside that
- (IBAction)btnDropdownclick:(UIButton*)sender
{
NSIndexPath *indesss = [NSIndexPath indexPathForItem:sender.tag-300 inSection:0];
CollectionViewCell *cell = (CollectionViewCell*) [_InnercollectionView cellForItemAtIndexPath:indesss];
_flag =indesss.item;
shouldCellBeExpanded = !shouldCellBeExpanded;
if(shouldCellBeExpanded)
{
[sender setImage:[UIImage imageNamed:#"uparrow.png"] forState:UIControlStateNormal];
}
else
{
[sender setImage:[UIImage imageNamed:#"downarrow.png"] forState:UIControlStateNormal];
}
cell.shouldCellBeExpanded = !cell.shouldCellBeExpanded ;
[_InnercollectionView performBatchUpdates:^{
[cell.tabelView reloadData];
} completion:^(BOOL finished) {
}];
}
below is code in cell class
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(_shouldCellBeExpanded){
_heightcheckview.constant = _tabelView.contentSize.height+120;
_tblheight.constant = _tabelView.contentSize.height+20;
}
else
{
_tabelView.scrollsToTop = YES;
_heightcheckview.constant = 195;
_tblheight.constant = 105;
}
if (tableView == _tblNoti) {
static NSString *MyIdentifier = #"noticell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
// self.tblheight .constant = tableView.contentSize.height;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] ;
}
// FoodDescModalClass *orderDataTypess;
if(!(self.arrayforNoti.count == 0))
{
NSDictionary *diction = [self.arrayforNoti objectAtIndex:indexPath.row];
UILabel *lbl = (UILabel*)[cell.contentView viewWithTag:2345];
lbl.text = [diction valueForKey:#"data"];
}
return cell;
}
else if (tableView == _tabelView){
static NSString *MyIdentifier = #"maineecell";
CollTableViewCell *cells = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
// self.tblheight .constant = tableView.contentSize.height;
if (cells == nil)
{
cells = [[CollTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] ;
}
if(_havecomment)
{
if(indexPath.row == self.arrayforitems.count)
{
UITableViewCell* celld = [tableView dequeueReusableCellWithIdentifier:#"commentcell"];
UILabel *lblcomment = [celld.contentView viewWithTag:4545];
lblcomment.text = _finalcomment;
lblcomment.layer.borderWidth = 1.0f ;
lblcomment.layer.cornerRadius = 4.0f ;
lblcomment.layer.masksToBounds = YES;
return celld;
}else{
NSDictionary*dict = [self.arrayforitems objectAtIndex:indexPath.row];
cells.lblName.text= [dict valueForKey:#"item"];
cells.lblPrice.text = [dict valueForKey:#"price"];
cells.lblquantity.text = [dict valueForKey:#"qty"];
NSString*type = [dict valueForKey:#"type"];
if([type isEqualToString:#"1"])
{
cells.imgveg.image=[UIImage imageNamed:#"veg"];
}
else if([type isEqualToString:#"2"])
{
cells.imgveg.image=[UIImage imageNamed:#"nonveg"];
}
else
{
cells.imgveg.image=[UIImage imageNamed:#"drink.png"];
}
cells.lblquantity.layer.borderWidth = 1.0f ;
cells.lblquantity.layer.cornerRadius = 4.0f ;
cells.lblquantity.layer.masksToBounds = YES;
}
}
else{
NSDictionary*dict = [self.arrayforitems objectAtIndex:indexPath.row];
cells.lblName.text= [dict valueForKey:#"item"];
cells.lblPrice.text = [dict valueForKey:#"price"];
cells.lblquantity.text = [dict valueForKey:#"qty"];
NSString*type = [dict valueForKey:#"type"];
if([type isEqualToString:#"1"])
{
cells.imgveg.image=[UIImage imageNamed:#"veg"];
}
else if([type isEqualToString:#"2"])
{
cells.imgveg.image=[UIImage imageNamed:#"nonveg"];
}
else
{
cells.imgveg.image=[UIImage imageNamed:#"drink.png"];
}
cells.lblquantity.layer.borderWidth = 1.0f ;
cells.lblquantity.layer.cornerRadius = 4.0f ;
cells.lblquantity.layer.masksToBounds = YES;
}
return cells;
}
else
{
return nil;
}}
screen shots are below
follow in sequence
http://prntscr.com/du4p2f
http://prntscr.com/du4p00
http://prntscr.com/du4q1t

How to Hide UIButton in tableView after getting certain JSON response

Here in this tableView cell i have created a button i want to hide that button after getting response "1". I am doing it in following way but not working still the cell is showing the button.How would i do that.
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
MyVideos *myvidoeclips = [park objectAtIndex:indexPath.row];
UILabel *lbl2=(UILabel*)[cell viewWithTag:777];
NSString *stateus = [myvidoeclips valueForKey:#"state"];
if([stateus isEqual: #"0"]){
[lbl2 setText:#"Under Moderation"];
}
if([stateus isEqual: #"1"]){
[lbl2 setText:#"Published"];
}
if([stateus isEqual: #"4"]){
[lbl2 setText:#"Rejected"];
}
lbl2.textColor=[UIColor whiteColor];
// Here is my button which i want to hide
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(216, 130, 64, 30)];
NSString *strFlagValue = [[NSString alloc]init];
strFlagValue = [myvidoeclips valueForKey:#"state"];
if ([strFlagValue isEqualToString:#"1"])
{
flag = true;
}
else
{
flag = false;
}
if (flag)
{
button.hidden = true;
}
else
{
button.hidden = false;
}
[button addTarget:self action:#selector(yourEditButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; button.tag = indexPath.row;
[button setImage:[UIImage imageNamed:#"btn-details.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:button];
NSLog(#"sender.tag cell is%ld ",(long)button.tag);
}
In cellForRowAtIndex check flag.
Flag will be true or false depending upon your JSON response ( Array / Dictionary )
BOOL flag;
NSString *strFlagValue = [[NSString alloc]init];
strFlagValue = [[array objectAtIndex:indexPath.row] valueForKey:#"Key_From_You_Get_1_Or_0"];
if ([strFlagValue isEqualToString:#"1"])
{
flag = true;
}
else
{
flag = false;
}
if (flag)
{
cell.button.hidden = true;
}
else
{
cell.button.hidden = false;
}
Also check your cell in cellForRowAtIndex must be reusable with identifier.
If you are sure to get "1" or "0" every time from JSON(Array). then below sort code is enough.
BOOL flag = [[[array objectAtIndex:indexPath.row] valueForKey:#"Key_From_You_Get_1_Or_0"] boolValue];
cell.button.hidden = flag;
Whole cellForRowAtIndexPath ( Logic you are writing in your question at wrong method )
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"ID_CustomCell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = (CustomCell *)[[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
BOOL flag = [[[array objectAtIndex:indexPath.row] valueForKey:#"Key_From_You_Get_1_Or_0"] boolValue];
cell.btn1.hidden = flag;
NSString *strFlagValue = [[NSString alloc]init];
strFlagValue = [[array objectAtIndex:indexPath.row] valueForKey:#"Key_From_You_Get_1_Or_0"];
if ([strFlagValue isEqualToString:#"1"])
{
flag = true;
}
else
{
flag = false;
}
if (flag)
{
cell.btn1.hidden = 1;
}
else
{
cell.btn1.hidden = 0;
}
return cell;
}
For static table cells, create an IBOutlet of UIButton and hide while checking condition using json data.
For dynamic table cells, need to identify the row number for which button needs to be hidden.
Example :- There is an array contains multiple dictionary.
NSDictionary* dict = [array objectAtIndex:indexPath.row];
BOOL isButtonHidden = [dict objectForKey:#"KeyName"];
cell.button.hidden = isButtonHidden
Hope this solution help you..Thanks

UICollectionView cell disappears on scroll

I have two collectionViews. A collectionViewController and another collectionView in the header. When I scroll down the collectionViewController, the collectionView cells of the the header collectionView disappear. There is also a segControl in the header that changes the collectionViewController cells and this also makes the header collectionView cells disappear. When the controller appears all the cells are present, BUT when i wither scroll of select the segControl the header Collection View cells disappear. The collectionViewController works fine, just the one in the header is messed up.
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (collectionView == self.collectionView) {
return [self.dataArray count];
}
return [self.groupArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if (collectionView != self.collectionView) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"socialCell" forIndexPath:indexPath];
PFObject *group = [self.groupArray objectAtIndex:indexPath.row];
UILabel *label = (UILabel *) [cell viewWithTag:55];
label.text = [group objectForKey:#"Title"];
return cell;
}
userPostCell *postCell = (userPostCell *) [collectionView dequeueReusableCellWithReuseIdentifier:#"postCell" forIndexPath:indexPath];
userPictureCell *pictureCell = (userPictureCell *) [collectionView dequeueReusableCellWithReuseIdentifier:#"pictureCell" forIndexPath:indexPath];
userEventCell *eventCell = (userEventCell *) [collectionView dequeueReusableCellWithReuseIdentifier:#"eventCell" forIndexPath:indexPath];
PFObject *temp = [self.dataArray objectAtIndex:indexPath.row];
if (self.dataArray == self.postsArray) {
postCell.postLabel.text = [temp objectForKey:#"stringPost"];
[self changeToCircle:postCell.profileImage];
if ([temp objectForKey:#"Event"] == nil) {
[postCell.noEventNameButton setTitle:[temp objectForKey:#"User_Name"] forState:UIControlStateNormal];
postCell.noEventNameButton.tag = indexPath.row;
postCell.nameButton.hidden = true;
postCell.noEventNameButton.hidden = false;
}
else{
[postCell.nameButton setTitle:[temp objectForKey:#"User_Name"] forState:UIControlStateNormal];
postCell.nameButton.tag = indexPath.row;
postCell.noEventNameButton.hidden = true;
postCell.nameButton.hidden = false;
//[postCell.eventButton addTarget:self action:#selector(eventPage:) forControlEvents:UIControlEventTouchUpInside];
}
[postCell.eventButton setTitle:[temp objectForKey:#"Event"] forState:UIControlStateNormal];
NSString *createdTime = [NSDateFormatter localizedStringFromDate: temp.createdAt dateStyle: NSDateFormatterNoStyle timeStyle: NSDateFormatterShortStyle];
[postCell.timeButton setTitle:createdTime forState:UIControlStateNormal];
PFFile *imageFile = [temp objectForKey:#"profileImage"];
NSData *data = [imageFile getData];
postCell.profileImage.image = [UIImage imageWithData:data];
NSArray *likeArray = [temp objectForKey:#"likes"];
NSString *likeString = [NSString stringWithFormat:#"%lu Likes", (unsigned long)likeArray.count];
if ([likeArray containsObject:[PFUser currentUser].objectId]) {
postCell.likeButton.hidden = true;
}
else{
postCell.likeButton.hidden = false;
}
NSArray *commentArray = [temp objectForKey:#"Comments"];
NSString *commentString = [NSString stringWithFormat:#"%lu Comments", (unsigned long)commentArray.count];
[postCell.likesButton setTitle:likeString forState:UIControlStateNormal];
[postCell.commentsButton setTitle:commentString forState:UIControlStateNormal];
postCell.eventButton.tag = indexPath.row;
postCell.likeButton.tag = indexPath.row;
postCell.commentsButton.tag = indexPath.row;
postCell.likesButton.tag = indexPath.row;
[postCell.likesButton addTarget:self action:#selector(likesPage:) forControlEvents:UIControlEventTouchUpInside];
[postCell.likeButton addTarget:self action:#selector(like:) forControlEvents:UIControlEventTouchUpInside];
[postCell.commentsButton addTarget:self action:#selector(commentsPage:) forControlEvents:UIControlEventTouchUpInside];
[postCell setUserInteractionEnabled:YES];
return postCell;
}
if (self.dataArray == self.personImages) {
UIImage *personImage = [self.dataArray objectAtIndex:indexPath.row];
pictureCell.userImage.image = personImage;
return pictureCell;
}
if (self.dataArray == self.eventsArray) {
[eventCell.userEvent setTitle:[temp objectForKey:#"Title"] forState:UIControlStateNormal];
eventCell.userEvent.tag = indexPath.row;
[eventCell.userEvent addTarget:self action:#selector(eventPage:) forControlEvents:UIControlEventTouchUpInside];
[eventCell.userGroup setTitle:[temp objectForKey:#"Group_Name"] forState:UIControlStateNormal];
eventCell.userGroup.tag = indexPath.row;
[eventCell.userGroup addTarget:self action:#selector(groupPage:) forControlEvents:UIControlEventTouchUpInside];
return eventCell;
}
return postCell;
}
The Seg Method:
- (IBAction)segControl:(id)sender {
UISegmentedControl *segment = (UISegmentedControl *) sender;
if (segment.selectedSegmentIndex == 0) {
self.dataArray = self.postsArray;
[self.collectionView reloadData];
}
if (segment.selectedSegmentIndex == 1) {
self.dataArray = self.personImages;
[self.collectionView reloadData];
}
if (segment.selectedSegmentIndex == 2) {
self.dataArray = self.eventsArray;
[self.collectionView reloadData];
}
}
it's late but this will help for others
i also had similar problem , i just replaced [self.myCollectionView reloadData] with [self.myCollectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; to refresh the collectionview and it shows all cells, you can try it.

UITableView calling the another UITableView cellForRowAtIndexPath

I have two UIViewControllers with tableview. When the first cell loads in the second UIViewController it calls the cellForRowAtIndexPath in the same class but when it loads the second cell it calls the first viewControllers cellForRowAtIndexPath.
My code as follows:
SecondViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NotificationsTableViewCell *cell = [self.notificationsTableView dequeueReusableCellWithIdentifier:#"NotificationCell"];
if(cell == nil)
{
cell = [[NotificationsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"NotificationCell"];
}
NSMutableDictionary *cellData = [self.databaseCall transactionFromDatabase:indexPath.row];
NSLog(#"%#", cellData);
cell.goalNameLabel.text = [cellData objectForKey:#"categoryName"];
NSString *cardTypeId = [cellData objectForKey:#"cardTypeId"];
NSString *tipsId = [cellData objectForKey:#"tipsId"];
if([self.defaultCardTypeId containsObject:cardTypeId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultCardTypeId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultCardTypeId addObject:cardTypeId];
}
if([self.defaultTipId containsObject:tipsId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultTipId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultTipId addObject:tipsId];
}
if([cardTypeId isEqualToString:#"1"])
{
UIImage *cellImage = [UIImage imageNamed:#"icon2.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = #"GOOD TO KNOW";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:252/255.0 green:171/255.0 blue:19/255.0 alpha:1];
}
if([cardTypeId isEqualToString:#"2"])
{
UIImage *cellImage = [UIImage imageNamed:#"icon1.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = #"TO CONSIDER";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:0/255.0 green:191/255.0 blue:243/255.0 alpha:1];
}
cell.notificationCard.layer.cornerRadius = 5;
// Configure the cell...
return cell;
}
FirstViewController:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GoalsCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"GoalsListCell" forIndexPath:indexPath];
if(cell == nil)
{
cell = [[GoalsCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"GoalsListCell"];
}
NSInteger indexOfCategory = [self.databaseCall.arrColumnName indexOfObject:#"CategoryName"];
NSInteger indexOfImage = [self.databaseCall.arrColumnName indexOfObject:#"CategoryImage"];
NSInteger indexOfActive = [self.databaseCall.arrColumnName indexOfObject:#"coulmn"];
//Assigning the contents of cell
cell.goalName.text = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]];
NSString *categoryImage = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfImage]];
NSString *activeStatus = [NSString stringWithFormat:#"%#", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfActive]];
UIImage *cellImage = [UIImage imageNamed:categoryImage];
cell.goalImage.image = cellImage;
[cell.favouriteButton addTarget:self action:#selector(favouriteButtonPressed:) forControlEvents:UIControlEventTouchDown];
NSMutableString *selectedRowImage = [[NSMutableString alloc] initWithString:#""];
//Checking whether the category is selected by user or not
if([activeStatus isEqualToString:#"yes"])
{
selectedRowImage = [NSMutableString stringWithFormat:#"starsel.png"];
}
else
{
selectedRowImage = [NSMutableString stringWithFormat:#"stardef.png"];
}
UIImage *favouriteIconImage = [UIImage imageNamed:selectedRowImage];
[cell.favouriteButton setBackgroundImage:favouriteIconImage forState:UIControlStateNormal];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
return cell;
}
Thanks in advance.
First of all i would say sorry for this stupid question.
The problem is due to the tableview datasource as specifies by #Paulw11, #Onik IV, #Kannan Vora. The secondViewController tableView has the datasource of firstViewController.

UIButton not select the correct cell

in my tableview I have a button in the custom cell
I used the delegates to take an action to the button
The button image changes only on the selected cell
My problem is this:
When I press the button happens:
the selected cell is working properly and the button changes correctly (correct)
the second immediately after the selected cell does not change the button (corrected)
the third cell repeats the action of the selected cell (wrong)
This is repeated endlessly do not understand why
 The button should change only the selected cell and not on other non-selected
Can you help me please?
-(void)ButtonPressedGoPoint:(FFCustomCellWithImage *)custom button:(UIButton *)gopointpressed {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:#"it_IT"]];
NSNumber *likeCount = [numberFormatter numberFromString:custom.CountGoPoint.text];
if (!custom.AddGoPoint.selected) {
NSLog(#"TastoSelezionato");
likeCount = [NSNumber numberWithInt:[likeCount intValue] + 1];
custom.CountGoPoint.text = [NSString stringWithFormat:#"%#", likeCount];
[custom.AddGoPoint setBackgroundImage:[UIImage imageNamed:#"FFIMG_Medal_Blu"] forState:UIControlStateNormal];
}
else {
if ([likeCount intValue] > 0) {
likeCount = [NSNumber numberWithInt:[likeCount intValue] - 1];
custom.CountGoPoint.text = [NSString stringWithFormat:#"%#", likeCount];
}
NSLog(#"TastoDeselezionato");
[custom.AddGoPoint setBackgroundImage:[UIImage imageNamed:#"FFIMG_MedalADD"] forState:UIControlStateNormal];
}
custom.AddGoPoint.selected = !custom.AddGoPoint.selected;
}
This is my implementation of the tableview
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.PostDetails = [ArrayforPost objectAtIndex:indexPath.row];
static NSString *IdentificazioneCellaIMG = #"CellaIMG";
FFCustomCellWithImage * CellaIMG = (FFCustomCellWithImage * )[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCellaIMG];
if (CellaIMG == nil) {
CellaIMG = [[FFCustomCellWithImage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IdentificazioneCellaIMG ];
}
CellaIMG.delegate = self;
CellaIMG.tag = indexPath.row;
[CellaIMG.AddGoPoint setTag:indexPath.row];
if ([self AssignedGoPointToPost:self.PostDetails]) {
CellaIMG.AddGoPoint.selected =YES;
[CellaIMG.AddGoPoint setImage:[UIImage imageNamed:#"FFIMG_Medal_Blu"] forState:UIControlStateNormal];
} else {
CellaIMG.AddGoPoint.selected =NO;
[CellaIMG.AddGoPoint setImage:[UIImage imageNamed:#"FFIMG_MedalADD"] forState:UIControlStateNormal];
}
NSString *FotoPostSocial = [self.PostDetails objectForKey:FF_POST_IMMAGINE];
CellaIMG.FotoPost.file = (PFFile *)FotoPostSocial;
[CellaIMG.FotoPost loadInBackground];
CellaIMG.FotoPost.layer.masksToBounds = YES;
CellaIMG.FotoPost.layer.cornerRadius = 2.0f;
CellaIMG.FotoPost.contentMode = UIViewContentModeScaleAspectFill;
CellaIMG.backgroundCell.layer.masksToBounds = YES;
CellaIMG.backgroundCell.layer.cornerRadius = 2.0f;
CellaIMG.backgroundCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
CellaIMG.backgroundCell.layer.borderWidth = 1.0f;
CellaIMG.backgroundCell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
CellaIMG.LeggiCommentoButton.layer.cornerRadius = 2.0f;
CellaIMG.FotoProfilo.layer.masksToBounds = YES;
CellaIMG.FotoProfilo.layer.cornerRadius = 25.0f;
CellaIMG.FotoProfilo.contentMode = UIViewContentModeScaleAspectFill;
CellaIMG.TestoPost.font = [UIFont fontWithName:#"Helvetica" size:14.0f];
NSString *text = [self.PostDetails objectForKey:FF_POST_TEXT];
CellaIMG.TestoPost.text = text;
[CellaIMG.TestoPost setLineBreakMode:NSLineBreakByTruncatingTail];
NSString *NomeUser = [[self.PostDetails objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_NOMECOGNOME];
CellaIMG.NomeUtente.text = NomeUser;
NSString *ImmagineUtente = [[self.PostDetails objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_FOTOPROFILO];
CellaIMG.FotoProfilo.file = (PFFile *)ImmagineUtente;
[CellaIMG.FotoProfilo loadInBackground];
if (CellaSelezionata == indexPath.row) {
CGFloat AltezzaLabel = [self valoreAltezzaCella: indexPath.row];
CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, AltezzaLabel); }
else {
CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, 65);
}
return CellaIMG;
}
}

Resources