Done button in UIToolbar not working - objective-c

So I'm creating a UIToolbar to go ontop of a UIKeyboard, and the done button works perfectly until I call a method to reload my UITableView. Then everything still works except the callback function for the done button, (i.e. done:). Does anybody know why this might be? I'm using the following code to create a custom UITableView subclass with the toolbar...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section != 1){
if (indexPath.row != 2){
static NSString *CellIdentifier = #"EditableCell";
EditableCell *editableCell = (EditableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (editableCell == nil) {
editableCell = [[EditableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[_myTextField setPlaceholder:#"$0.00"];
[_myTextField setKeyboardType:UIKeyboardTypeDecimalPad];
UIToolbar *toolbar = [[UIToolbar alloc] init];
[toolbar setBarStyle:UIBarStyleBlackTranslucent];
[toolbar sizeToFit];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(resignKeyboard)];
doneButton.title = #"Done";
NSArray *itemsArray = [NSArray arrayWithObjects:doneButton, nil];
[toolbar setItems:itemsArray];
[_myTextField setInputAccessoryView:toolbar];
}
[_myTextField setReturnKeyType:UIReturnKeyNext];
}
else if (indexPath.section == 1){
[_myTextField setPlaceholder:#"Describe this food..."];
[_myTextField setReturnKeyType:UIReturnKeyDone];
}
_myTextField.delegate = self;
return editableCell;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if([text isEqualToString:#"\n"])
[textView resignFirstResponder];
else{
NSMutableString *textFieldString = [[NSMutableString alloc] initWithString:textView.text];
[textFieldString replaceCharactersInRange:range withString:text];
_textViewString = #"";
_textViewString = textFieldString;
_foodDescription = textFieldString;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
return YES;
}

Related

How to add the current String in the previous tableview from UIAlertAction in objective c

I am new in iOS and I am facing problem regarding to show the String in the previous Tableview cell in the same UIViewController
As shown in Image
When I click on ok I want to add full instead of label
When I am adding string in cellforrowatindexpath it get replace in all tableview cell. I want to replace label text according to selected index.
My code is look like this.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == customaudittable)
{
static NSString *STI=#"STI";
AuditTableViewCell *cell = (AuditTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"AuditTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType=UITableViewCellAccessoryNone;
}
cell.audittitlelbl.text=[NSString stringWithFormat:#"%#",[idarray objectAtIndex:indexPath.row]];
cell.auditdesclbl.text=[NSString stringWithFormat:#"%#",[namearray objectAtIndex:indexPath.row]];
return cell;
}
if(tableView == FPNtable)
{
static NSString *STI=#"STI";
FPNTableViewCell *cell = (FPNTableViewCell *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:STI];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"FPNTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.accessoryType=UITableViewCellAccessoryNone;
}
cell.fulllbl.text=[NSString stringWithFormat:#"%#",[idarrayFPN objectAtIndex:indexPath.row]];
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == Audittable)
{
NSString *listString;
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
listString = [defaults objectForKey:#"ListString"];
AuditTableViewCell *cell = (AuditTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.listlbl.text=listString;
midString =[NSString stringWithFormat:#"%#",[midarray objectAtIndex:indexPath.row]];
[self serverconnectionFPN];
// Audittable.alpha=0.24;
UIViewController *controller = [[UIViewController alloc]init];
CGRect rect;
if (idarrayFPN.count < 4) {
rect = CGRectMake(0, 0, 272, 160);
[controller setPreferredContentSize:rect.size];
}
else if (idarrayFPN.count < 6){
rect = CGRectMake(0, 0, 272, 300);
[controller setPreferredContentSize:rect.size];
}
else if (idarrayFPN.count < 8){
rect = CGRectMake(0, 0, 272, 200);
[controller setPreferredContentSize:rect.size];
}
else {
rect = CGRectMake(0, 0, 272, 250);
[controller setPreferredContentSize:rect.size];
}
alert =
[UIAlertController alertControllerWithTitle:#"AuditCheckList"
message:#""
preferredStyle:UIAlertControllerStyleAlert];
FPNTable = [[UITableView alloc]initWithFrame:rect];
FPNTable.delegate = self;
FPNTable.dataSource = self;
[controller.view addSubview:FPNTable];
[controller.view bringSubviewToFront:FPNTable];
[controller.view setUserInteractionEnabled:YES];
[FPNTable setUserInteractionEnabled:YES];
[FPNTable setAllowsSelection:YES];
[alert setValue:controller forKey:#"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
[Audittable reloadData];
}];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
if (tableView == FPNTable) {
FPNTableViewCell *cell = (FPNTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.circleimg.image=[UIImage imageNamed:#"CircleClick.png"];
NSString *ListString;
ListString =[NSString stringWithFormat:#"%#",[idarrayFPN objectAtIndex:indexPath.row]];
NSLog(#"List Item =%#",ListString);
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:ListString forKey:#"ListString"];
}
}
-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:
(NSIndexPath *)indexPath {
FPNTableViewCell *cell = (FPNTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.circleimg.image=[UIImage imageNamed:#"Circleicon.png"];
}
Thanks in Advance!
haven't got the time to read all your code, but I guess that your question is understood, what you can do which is the easiest way, is that when the user selects the option from the UIAlertAction, you can save that option in a global string in the class, then assign the "Label" UILabel to that global string, finally you need to reload your UITableView
I hope that helps

Uncheck (unfavorite) items in Favorites Table View

I have a tableview that displays a list of "favorited" items. Users favorite items in another tableview, and favorited items are listed in this tableview (FavoritesTableView.m).
For some reason, I can't get checked items (favorited items) to "uncheck" from the FavoritesTableView? What am I missing?
See the .m file below...
FavoritesViewController.h
#import <UIKit/UIKit.h>
#import "StrainTableCell.h"
#interface FavoritesViewController : UITableViewController
{
}
#property (strong, nonatomic) NSArray *favoritesArrayset;
#property (strong, nonatomic) IBOutlet UITableView *favoritesTable;
#property (nonatomic, strong) NSMutableArray * favoritesArray;
- (IBAction)backbuttonpressed: (UIBarButtonItem *)sender;
#end
FavoritesViewController.m
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
if (favoritesArray == Nil)
{
favoritesArray = [[NSMutableArray alloc] init];
}
else
{
[favoritesArray removeAllObjects];
}
NSData *dataSave = [[NSUserDefaults standardUserDefaults] objectForKey:#"strains"];
if (dataSave != Nil)
{
favoritesArrayset = [NSKeyedUnarchiver unarchiveObjectWithData:dataSave];
for (NSDictionary *item in favoritesArrayset)
{
BOOL isChecked = [[item objectForKey:#"checked"] boolValue];
if (isChecked == YES )
{
[favoritesArray addObject:item];
}
}
}
[favoritesTable reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return favoritesArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *Strains = [favoritesArray copy];
NSArray *dataArray = [favoritesArray copy];
static NSString *strainTableIdentifier = #"StrainTableCell";
StrainTableCell *cell = (StrainTableCell *)[tableView dequeueReusableCellWithIdentifier:strainTableIdentifier];
if (cell == nil)
{
cell = [[StrainTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strainTableIdentifier] ;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"StrainTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.titleLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Title"];
cell.descriptionLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Description"];
cell.ratingLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Rating"];
cell.ailmentLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Ailment"];
cell.actionLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Action"];
cell.ingestLabel.text = [[Strains objectAtIndex:indexPath.row] objectForKey:#"Ingestion"];
cell.whatCellamI = [NSNumber numberWithInt:indexPath.row];
NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.text = [item objectForKey:#"text"];
[item setObject:cell forKey:#"StrainTableCell"];
}
BOOL checked = [[item objectForKey:#"checked"] boolValue];
UIImage *image = (checked) ? [UIImage imageNamed:#"checked.png"] : [UIImage imageNamed:#"unchecked.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:#selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
StrainDetailViewController *detailViewController = [[StrainDetailViewController alloc]
initWithNibName:#"StrainDetailViewController" bundle:nil];
detailViewController.title = [[favoritesArray objectAtIndex:indexPath.row] objectForKey:#"Title"];
detailViewController.strainDetail = [favoritesArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 82;
}
- (IBAction)backbuttonpressed:(id)sender
{
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)checkButtonTapped:(id)sender event:(id)event
{
NSLog(#"made it here and event is %#",event);
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.favoritesTable];
NSIndexPath * indexPath ;
indexPath = [self.favoritesTable indexPathForRowAtPoint: currentTouchPosition];
NSLog(#"indexpath is below");
NSLog(#"%#",indexPath);
if (indexPath != Nil)
{
NSMutableDictionary *item = [favoritesArray objectAtIndex:indexPath.row];
BOOL isItChecked = [[item objectForKey:#"checked"] boolValue];
/*
if (isItChecked == NO) {
NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
NSMutableArray *tmpArray2 = [[NSMutableArray alloc] initWithArray:[favoritesArray allObjects]];
NSString *text1 = [item objectForKey:#"Title"];
for (NSDictionary * object in tmpArray2) {
NSString *text2 = [object objectForKey:#"Title"];
if (![text1 isEqualToString:text2]) {
[tmpArray addObject:object];
}
}
// [favoritesArray removeAllObjects];
favoritesArray = [tmpArray copy];
}
*/
NSMutableArray *quickArray = [[NSMutableArray alloc] initWithArray:favoritesArray];
[quickArray replaceObjectAtIndex:indexPath.row withObject:item];
[item setObject:[NSNumber numberWithBool:!isItChecked] forKey:#"checked"];
favoritesArray = [quickArray copy];
// [self.favoritesArray addObject:item];
// NSLog(#"you have added %d items to favorites", self.favoritesArray.count);
[favoritesTable reloadData];
}
#end
In your .h take one NSMutableDictionary and do property to it.
In your .m synthesize it,and in viewdidLoad alloc the Dictionary.
Now put this below code in CellForRowAtIndex
if([idDictonary objectForKey:[NSString stringWithFormat:#"%d",[indexPath row]]])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
and put this below code in DidSelectRowAtIndex
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
[idDictonary setValue:[dataArray objectAtIndex:indexPath.row] forKey:[NSString stringWithFormat:#"%d",[indexPath row]]];
}
else
{
if([idDictonary objectForKey:[NSString stringWithFormat:#"%d",[indexPath row]]])
{
[idDictonary removeObjectForKey:[NSString stringWithFormat:#"%d",[indexPath row]]];
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
[myTableView reloadData];
NSLog(#"idDictonary = %#",idDictonary);
i hope this will helps u Brittany...
Every time -tableView:cellForRowAtIndexPath: runs, you create a new button, set it to the desired properties and … throw it away. (Seems to be the running joke this week.) You have to use the existing button.

UIButton subview in UITableViewCell doesn't hide as expected

My recent frustration is a UIButton subview in each UITableViewCell of my UITableView which I want to setHidden: according to a specific clause for each indexPath. My code is pretty much the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[self initCell:cell forIndexPath:indexPath];
}
[self updateCell:cell forIndexPath:indexPath];
return cell;
}
and the init and update methods are the following:
- (void)initCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
...
UIButton *btnMy = [UIButton buttonWithType:UIButtonTypeCustom];
btnMy.tag = kButtonMyTag;
[btnMy setFrame:CGRectMake(170, 45, 100, 30)];
[btnMy setBackgroundImage:[UIImage imageNamed:#"btn_image"] forState:UIControlStateNormal];
btnMy.adjustsImageWhenHighlighted = YES;
[btnMy setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btnMy.titleLabel.font = [UIFont fontWithName:#"MyFont" size:14];
[btnMy addTarget:self action:#selector(btnMyPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btnMy];
UIImageView *imgViewAccessory = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"table_accessory"]];
cell.accessoryView = imgViewAccessory;
[imgViewAccessory release];
}
- (void)updateCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
UIButton *btnMy = (UIButton *)[cell viewWithTag:kButtonMyTag];
MyObject *object = (MyObject *)[self.dataSource objectAtIndex:indexPath.row];
if(object.meetsCondition)
{
btnMy.hidden = NO;
}
else
{
btnMy.hidden = YES;
}
...
}
The frustrating result is that when scrolling the button shows and hides randomly and not as expected according the if clause in the updateCell method.
Any help would be much appreciated. Thanks in advance!
You should make custom cell and depending upon the condition show and hide the button
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *nib;
static NSString *cellIdentifier= #"cell";
UITableViewCell *theCell = [self.tblView dequeueReusableCellWithIdentifier:cellIdentifier];
if([theCell.contentView subviews]){
for(UIView *view in [theCell.contentView subviews]){
[view removeFromSuperview];
}
}
if(theCell== nil)
{
nib = [[NSBundle mainBundle] loadNibNamed:#"Your custom cell name" owner:self options:nil];
theCell = [nib objectAtIndex:0];
theCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UIButton *btn=(UIButton*)[theCell.contentView viewWithTag:101];
if(yourcondition)
//hide button
else
//show button
}
This will do
Use this code in your CellForRowAtIndexPath Also.
MyObject *object = (MyObject *)[self.dataSource objectAtIndex:indexPath.row];
if(object.meetsCondition) {
btnMy.hidden = NO;
}
else {
btnMy.hidden = YES;
}

Check marks are unchecked when scroll the tableview

i am using tableview and display data. in the table view all checkMark items sent mail. but when scroll the table check marks are unchecked. i don't want un check when scroll the table. please help me. i am developing below code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CustomCellIdentifier = #"CustomCellIdentifier ";
CaptureCell *cell = (CaptureCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CaptureCell"
owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CaptureCell class]])
cell = (CaptureCell *)oneObject;
}
if ([[[dataArray objectAtIndex:indexPath.row] objectForKey:#"CaptureId"]isEqualToString:[dict objectForKey:[[dataArray objectAtIndex:indexPath.row] objectForKey:#"CaptureId"]]])
{
cell.confirmMail.image = [UIImage imageNamed:#"mailConfirm.png"];
}
NSString *input;
input = [[dataArray objectAtIndex:indexPath.row]objectForKey:#"amount"];
[input stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//NSLog(#"after removing white spaces %#",input);
double price;
NSString *numberAsString = nil;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:#"en_US"];
[numberFormatter setLocale:gbLocale];
[gbLocale release];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
if ([[input stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]length]!=0)
{
NSLog(#"the input is***** %#",input);
price=[[input stringByReplacingOccurrencesOfString:#"$" withString:#""] doubleValue];
NSLog(#"the price is %f",price);
numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:price]];
NSLog(#"the numberAsString...... %#",numberAsString);
}
[numberFormatter release];
cell.eventNameLbl.text = [[dataArray objectAtIndex:indexPath.row]objectForKey:#"expenseType"];
cell.expenTypeLbl.text = [[dataArray objectAtIndex:indexPath.row]objectForKey:#"empName"];
cell.dataLbl.text = [[dataArray objectAtIndex:indexPath.row]objectForKey:#"Date"];
cell.amountLbl.text = numberAsString;
cell.billImage.image = [UIImage imageWithData:[[dataArray objectAtIndex:indexPath.row]objectForKey:#"image"]];
//[cell.textLabel setText:[NSString stringWithFormat:#"Row %d", indexPath.row]];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
NSIndexPath* selection = [tableView indexPathForSelectedRow];
if (selection && selection.row == indexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
// if([[[captureArray objectAtIndex:indexPath.row]objectForKey:#"eventName"]isEqualToString:[[selectedData objectAtIndex:indexPath.row]objectForKey:#"eventName"]])
// NSLog(#"Equal");
//[cell setEditing:YES animated:YES];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *selected = [dataArray objectAtIndex:indexPath.row];
if([tableView isEditing] == YES)
{
AppDelegate *sharedDelegate = [[UIApplication sharedApplication]delegate];
sharedDelegate.isEditCapture = YES;
sharedDelegate.findDate = YES;
NSString *imgDataStr = [[NSString alloc]initWithData:[[dataArray objectAtIndex:indexPath.row]objectForKey:#"image"] encoding:NSUTF8StringEncoding];
NSLog(#"imageStr%#",imgDataStr);
ExpensesCaptureViewController_iPhone *nextController = [[ExpensesCaptureViewController_iPhone alloc] initWithNibName:#"ExpensesCaptureViewController_iPhone" bundle:nil];
nextController.captureId = [[dataArray objectAtIndex:indexPath.row] objectForKey:#"CaptureId"];
[self.navigationController pushViewController:nextController animated:YES];
[imgDataStr release];
[nextController release];
if([selectedData count]>0)
{
[selectedData removeObject:selected];
}
}
else {
if ([[[dataArray objectAtIndex:indexPath.row] objectForKey:#"CaptureId"]isEqualToString:[dict objectForKey:[[dataArray objectAtIndex:indexPath.row] objectForKey:#"CaptureId"]]])
{
NSLog(#"sent items");
}
else {
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedData addObject:selected];
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
[selectedData removeObject:selected];
}
}
}
NSLog(#"DataObjects %d %#",[selectedData count] ,[[dataArray objectAtIndex:indexPath.row] objectForKey:#"eventName"]);
//[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
The problem that you scroll your tableView when - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method is called and you set
NSIndexPath* selection = [tableView indexPathForSelectedRow];
if (selection && selection.row == indexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
that means when you will scroll indexPath will be for the current row only so the checkmark at the current row will still checked but the all the other rows will enter the else condition and the checkmark will be removed.
To fix it you should make a do the following:
define the following property:
#property (nonatomic)BOOL isViewIsLoadedForTheFirstTime;
-(void)viewDidLoad
{
self.isViewIsLoadedForTheFirstTime = YES;
}
then replace these lines in the (cellForRow) method
if (selection && selection.row == indexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
to the following lines:
if (self.isViewIsLoadedForTheFirstTime) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.isViewIsLoadedForTheFirstTime = NO;
}
This will make you set the check mark only when the view loaded for the first time the when you will scroll it won't change.
I hope that will help you

Pushing data from one View to another

I have a table list of promotions held in an NSSet which I load into an array for the purpose of displaying the title/name on the cell. However I want to use the didselectrow method to push the selected promotion onto an individual promotion page. I've making promo.featuredArray = self.featuredArray however it doesn't seem to be passing the data. My code is as follows.
Promo list.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
Featured*featured = [self.featuredArray objectAtIndex:indexPath.row];
cell.textLabel.text = featured.details;
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.text = self.place.name;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Promo * promo= [[Promo alloc] initWithNibName:#"Promo" bundle:nil];
//Featured*featured = [self.featuredArray objectAtIndex:indexPath.row];
promo.featuredArray = self.featuredArray;
[self.navigationController pushViewController:promo animated:YES];
[promo release];
//[featured release];
}
Promo.m
#synthesize featuredArray, featured = __featured;
- (void)viewDidLoad
{
self.clearImage = [UIImage imageNamed:#"fav_icon.png"];
self.clearImagePressed = [UIImage imageNamed:#"fav_icon_sel.png"];
Featured*featured = [self.featuredArray init];
self.name.text = [NSString stringWithFormat:#"%#", __featured.name];
self.time.text = [NSString stringWithFormat:#"%#", __featured.time];
// self.description.text = [NSString stringWithFormat:#"%#", __featured.description];
self.placeName.text = [NSString stringWithFormat:#"%#", __featured.Place];
[super viewDidLoad];
if([__featured.imageURL hasPrefix:#"http"])
{
[self getImageForPlace];
}
// else
// {
// [self refreshImage];
// }
//
self.title = #"Promotion";
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_texture.png"]];
self.view.backgroundColor = background;
[background release];
[featured release];
}
It's probably this line:
Featured*featured = [self.featuredArray init];
This is wrong in many ways.
Making this a community wiki because I don't have time to write a full answer.