Keeping a track of selected cells - iphone

In my app, the user changes the fields that appear in a tableView depending on the cells selected by him/her. (FYI... I have permitted multiple cell selection.) Just when the user presses the back button, the program copies the textLabel of the selected cells to the placeholder of the parent viewController.
Here's the relevant section of my code:
- (void)willMoveToParentViewController:(UIViewController *)parent
{
int tempCount = 0;
for (int section = 0; section < 3; section++)
{
int rowMax;
if (section == 0)
rowMax = 3;
else if (section == 1)
rowMax = 5;
else if(section == 2)
rowMax = 3;
for(int row = 0; row < rowMax; row++)
{
NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:tempIndexPath];
if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
NSLog(#"tempCount = %d", tempCount);
tempCount++;
if (tempCount == 1)
chosenFieldsViewController.field0.placeholder = selectedCell.textLabel.text;
else if(tempCount == 2)
chosenFieldsViewController.field1.placeholder = selectedCell.textLabel.text;
else if(tempCount == 3)
chosenFieldsViewController.field2.placeholder = selectedCell.textLabel.text;
}
}
}
}
I realized that after selecting the cells if the tableView is scrolled down, the selected cells do not appear as placeHolder on the parentVC. From my analysis I think that once I scroll down, the cells are deleted from the memory. So despite the fact that the cells are selected, they fail to show up on the parent VC.
If so, why do I see the cells appear selected when I scroll up?
I would be grateful if somebody can suggest how I can keep a track of the selected cells even when the user scrolls.
Thanks.
Edit 1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if(selectedCell.accessoryType != UITableViewCellAccessoryCheckmark && count<3)
{
selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
count ++;
}
else if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
selectedCell.accessoryType = UITableViewCellAccessoryNone;
count--;
}
}
Edit 2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:#"CellForRow%dSection%d",indexPath.row, indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone; // VERY IMPORTANT
if (indexPath.section == 0)
{
switch(indexPath.row)
{
case 0:
cell.textLabel.text = #"Class A";
break;
case 1:
cell.textLabel.text = #"Class B";
break;
case 2:
cell.textLabel.text = #"Class C";
break;
default:
break;
}
}
if(indexPath.section == 1)
{
switch(indexPath.row)
{
case 0:
cell.textLabel.text = #"Class D";
break;
case 1:
cell.textLabel.text = #"Class E";
break;
case 2:
cell.textLabel.text = #"Class F";
break;
case 3:
cell.textLabel.text = #"Class G";
break;
case 4:
cell.textLabel.text = #"Class H";
break;
default:
break;
}
}
if(indexPath.section == 2)
{
switch (indexPath.row)
{
case 0:
cell.textLabel.text = #"Class I";
break;
case 1:
cell.textLabel.text = #"Class J";
break;
case 2:
cell.textLabel.text = #"Class K";
break;
default:
break;
}
}
return cell;
}

Declare a dictionary as,
#property (nonatomic, retain) NSMutableDictionary *selectedTextListDict;
In viewDidLoad,
NSMutableDictionary *selectedTextListDict = [[NSMutableDictionary alloc] init];
Then change these methods as,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if(selectedCell.accessoryType != UITableViewCellAccessoryCheckmark && count < 3)
{
NSString *rowKeyString = [NSString stringWithFormat:#"%d", indexPath.row];
NSString *sectionKeyString = [NSString stringWithFormat:#"%d", indexPath.section];
NSMutableDictionary *row = [self.selectedTextListDict valueForKey:sectionKeyString];
if (!row) {
row = [[NSMutableDictionary alloc] init];
}
[row setObject:selectedCell.textLabel.text forKey:rowKeyString];
[self.selectedTextListDict setObject:row forKey:sectionKeyString];
selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;
count ++;
}
else if(selectedCell.accessoryType == UITableViewCellAccessoryCheckmark)
{
NSString *rowKeyString = [NSString stringWithFormat:#"%d", indexPath.row];
NSString *sectionKeyString = [NSString stringWithFormat:#"%d", indexPath.section];
NSMutableDictionary *row = [self.selectedTextListDict valueForKey:sectionKeyString];
[row removeObjectForKey:rowKeyString];
if ([[row allKeys] count] == 0) {
[self.selectedTextListDict removeObjectForKey:sectionKeyString];
} else {
[self.selectedTextListDict setObject:row forKey:sectionKeyString];
}
selectedCell.accessoryType = UITableViewCellAccessoryNone;
count--;
}
}
- (void)willMoveToParentViewController:(UIViewController *)parent
{
NSArray *selectedTextSectionKeysList = [self.selectedTextListDict allKeys];
NSArray *sortedSelectedTextSectionKeysList = [selectedTextSectionKeysList sortedArrayUsingSelector:#selector(intValue)];
int tempCount = 0;
for (NSString *sectionString in sortedSelectedTextSectionKeysList) {
NSMutableDictionary *rowDict = [self.selectedTextListDict valueForKey:sectionString];
if (rowDict) {
NSArray *selectedTextRowKeysList = [rowDict allKeys];
NSArray *sortedSelectedTextRowKeysList = [selectedTextRowKeysList sortedArrayUsingSelector:#selector(intValue)];
for (NSString *rowString in sortedSelectedTextRowKeysList) {
tempCount++;
if (tempCount == 1)
chosenFieldsViewController.field0.placeholder = [rowDict valueForKey:rowString];
else if(tempCount == 2)
chosenFieldsViewController.field1.placeholder = [rowDict valueForKey:rowString];
else if(tempCount == 3)
chosenFieldsViewController.field2.placeholder = [rowDict valueForKey:rowString];
}
}
}
}
Edit 1:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"GoToModifyFieldsViewController"])
{
ModifyFieldsViewController *modifyFieldsViewController = segue.destinationViewController;
modifyFieldsViewController.chosenFieldsViewController = self;
field0.placeholder = #"";
field1.placeholder = #"";
field2.placeholder = #"";
if(self.selectedTextListDict)
self.selectedTextListDict = [[NSMutableDictionary alloc] init];
}
}
Declare a dictionary in ChosenFieldsViewController: as,
#property (nonatomic, retain) NSMutableDictionary *selectedTextListDict;
In viewDidLoad,
selectedTextListDict = [[NSMutableDictionary alloc] init];
Therefore, rather using self.selectedTextListDict, use: chosenFieldsViewController.selectedTextListDict in ModifyFieldsViewController.

-If so, why do I see the cells appear selected when I scroll up?
Because they get created automatically whenever they are about to appear. Every time you scroll up or down, cells get created or reused. When they disappear, they get destroyed or marked for reuse.

Related

using of two different type of custom cell in same table view?

thanks in advance.
in my app, i have a tableview, in which i have to use two different style of custom cell, i made two custom cell, and in tableView cellForRowAtIndexPath method i used two identifier for cell, even i tried for two section. but its not working. it is giving me "EXE BAD Excess" or some time other kind of error. below is my code.
Error : thread1_EXE_BAD_Access(code = 2 ,address 0 x 0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
//CatIdentifier
static NSString *CellIdentiFier = #"CatIdentifier";
static NSString *Cell1IdentiFier = #"CatIdentifier1";
if (indexPath.section == 0)
{
CommitteCell *cell = ( CommitteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentiFier];
if(cell == nil)
{
cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:#"CommitteeCell" owner:self options:nil] objectAtIndex:0];
}
if (indicator == 1)
{
cell.lblName.text = str;
}
else
{
cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];
}
cell.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell.backgroundView).image = img;
return cell;
}
else
{
Committee2Cell *cell1 = (Committee2Cell *)[tableView dequeueReusableCellWithIdentifier:Cell1IdentiFier];
if(cell1 == nil)
{
cell1 = (Committee2Cell *)[[[NSBundle mainBundle] loadNibNamed:#"Committee2Cell" owner:self options:nil] objectAtIndex:0];
}
cell1.lblPost1.text = strPost;
cell1.txtName.text = strName;
cell1.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell1.backgroundView).image = img;
return cell1;
}
}
section in tableview and rows in section method are as below.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 0:
return [arrayName count]-1;
break;
case 1:
return 1;
break;
default:
break;
}
return 0;
}
please if anyone can fine that where is my mistake . thanks again.
data of array and label is as below.
-(void)NewsParser:(NSMutableDictionary *)dic
{
NSLog(#"dic = %#",dic);
arrayName = [[NSMutableArray alloc]init];
arrayPost = [[NSMutableArray alloc]init];
arrayimage= [[NSMutableArray alloc]init];
strPost = [[NSString alloc]init];
strName = [[NSString alloc]init];
strPost = [[dic valueForKey:#"post"]objectAtIndex:8];
strName = [[dic valueForKey:#"name"]objectAtIndex:8];
NSLog(#"Name = %#",strName);
NSLog(#"Post = %#",strPost);
for(int i=0;i<[dic count]-1;i++)
{
[arrayName addObject:[[dic valueForKey:#"name"]objectAtIndex:i]];
[arrayPost addObject:[[dic valueForKey:#"post"]objectAtIndex:i]];
[arrayimage addObject:[[dic valueForKey:#"pic"]objectAtIndex:i]];
}
NSLog(#"array = %#",arrayName);
NSLog(#"array = %#",arrayPost);
NSLog(#"array = %#",arrayimage);
[table1 reloadData];
}
I think a cleaner approach would be to use a container view with two different kind of cells and then selectively show/hide the view relevant for that cell. This would be easier to code and maintain but might consume a little more memory.
You R making reUsable identifier as only once . Do something like this :
-(UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString* identifier;
if(indexPath.section == 0)
identifier = #"0";
else
identifier = #"1";
self.tableView.dataSource = self;
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];
if( cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;
if (indexPath.section == 0)
{
if(cell == nil)
{
cell = ( CommitteCell *)[[[NSBundle mainBundle] loadNibNamed:#"CommitteeCell" owner:self options:nil] objectAtIndex:0];
}
if (indicator == 1)
{
cell.lblName.text = str;
}
else
{
cell.lblName.text = [arrayName objectAtIndex:indexPath.row];
cell.lblPost.text = [arrayPost objectAtIndex:indexPath.row];
cell.picimg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arrayimage objectAtIndex:indexPath.row]]]];
}
cell.backgroundView = [[UIImageView alloc]init];
UIImage *img = [UIImage imageNamed:#"link-bg 2.png"];
((UIImageView *)cell.backgroundView).image = img;
return cell;
}
Use like follow its work in my code smoothly , if you need more help let me know :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(YOUR CONDITION HERE)
ShareActionViewCell *shareCell;
NSString *ShareCellId = [NSString stringWithFormat:#"ShareCell%d",indexPath.row];
shareCell = (ShareActionViewCell *)[tableView dequeueReusableCellWithIdentifier:ShareCellId];
if(!shareCell) {
shareCell = [[ShareActionViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ShareCellId];
}
shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
shareCell.ShareTitle.text = [NSString stringWithFormat:#"%#",[tbldata objectAtIndex:indexPath.row]];
} else {
CustCell *dataCell;
NSString *DataCellId = [NSString stringWithFormat:#"DataCell%d",indexPath.row];
dataCell = (CustCell *)[tableView dequeueReusableCellWithIdentifier:DataCellId];
if(!dataCell) {
dataCell = [[CustCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DataCellId];
}
shareCell.selectionStyle = UITableViewCellSelectionStyleNone;
shareCell.ShareTitle.text = [NSString stringWithFormat:#"%#",[tbldata objectAtIndex:indexPath.row]];
}
}
Suggested using -objectForKey for a Dictionary:
[[dic objectForKey:#"post"] objectAtIndex:8];
Make sure there is a NSArray object at name/post/ pic keyed to dic
And, in your for loop:
for(int i=0;i<[dic count]-1;i++)
{
[arrayName addObject:[[dic valueForKey:#"name"] objectAtIndex: i]];
[arrayPost addObject:[[dic valueForKey:#"post"]objectAtIndex:i]];
[arrayimage addObject:[[dic valueForKey:#"pic"]objectAtIndex:i]];
}
are you sure [dic count] <= [dic objectForKey:#"name"]?
add a nil to array will be crashed.
4.Where did you call the method -(void)NewsParser:(NSMutableDictionary *)dic;, If your data array is correct, maybe the [table1 reloadData]; crashed.

TableView isn't updating data even though it recognizes input?

So I have 5 rows and on selection they pass an integer with the row number to my second view controller.
Each number has its own array with items and should then return the amount of items for the row specified.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"MasterCell";
MasterCell *cell = (MasterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
if (radInt == 0) {
cell.textLabel.text = #"LM";
NSLog(#"My return should have been LM");
}
if (radInt == 1) {
cell.textLabel.text = #"Restauranger";
NSLog(#"My return should have been Rest");
}
if (radInt == 2) {
cell.textLabel.text = [shoppingArray objectAtIndex:indexPath.row];
}
if (radInt == 3) {
cell.textLabel.text = [annatArray objectAtIndex:indexPath.row];
}
//cell.textLabel.text = [listData objectAtIndex:[indexPath row]];
cell.imageView.image = [UIImage imageNamed:#"tab-icon1.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
This is my code just to test it out and it doesn't work. NSLOG works correctly but the data simply wount update... What have I done wrong? It Nslogs LM every time but it also has 1 in the log which is the selected row (radInt).
New approach
static NSString *CellIdentifier = #"MasterCell";
MasterCell *cell = (MasterCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil)
cell = [[MasterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (radInt == 0) {
cell.textLabel.text = #"LM";
NSLog(#"My return should have been LM");
}
else if (radInt == 1) {
cell.textLabel.text = #"Restauranger";
NSLog(#"My return should have been Rest");
}
else if (radInt == 2) {
cell.textLabel.text = [shoppingArray objectAtIndex:indexPath.row];
}
else if (radInt == 3) {
cell.textLabel.text = [annatArray objectAtIndex:indexPath.row];
}
else {
cell.textLabel.text = #"Noes";
}
//cell.textLabel.text = [listData objectAtIndex:[indexPath row]];
cell.imageView.image = [UIImage imageNamed:#"tab-icon1.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
The view before ----
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *enjoy = [[SecondViewController alloc] init];
if ([[array objectAtIndex:indexPath.row] isEqual:#"Livsmedel"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 0;
NSLog(#"0");
}
if ([[array objectAtIndex:indexPath.row] isEqual:#"Restauranger"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 1;
NSLog(#"1");
}
if ([[array objectAtIndex:indexPath.row] isEqual:#"Shopping"]) {
[enjoy setTitle:[array objectAtIndex:indexPath.row]];
enjoy.radInt = 2;
}
if ([[array objectAtIndex:indexPath.row] isEqual:#"Annat"]) {
enjoy.radInt = 3;
}
[self performSegueWithIdentifier:#"main" sender:self];
}
You don't actually need to implement didSelectRowAtIndexPath: if you connect the segue in the storyboard from the cell to the next controller. What you need to implement is prepareForSegue:. Your code should look something like this:
- (void)prepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender
{
NSInteger row = [self.tableView indexPathForSelectedRow].row;
SecondViewController *enjoy = segue.destinationViewController;
if ([[array objectAtIndex:row] isEqual:#"Livsmedel"]) {
[enjoy setTitle:[array objectAtIndex:row]];
enjoy.radInt = 0;
NSLog(#"0");
}
if ([[array objectAtIndex:row] isEqual:#"Restauranger"]) {
[enjoy setTitle:[array objectAtIndex:row]];
enjoy.radInt = 1;
NSLog(#"1");
}
if ([[array objectAtIndex:row] isEqual:#"Shopping"]) {
[enjoy setTitle:[array objectAtIndex:row]];
enjoy.radInt = 2;
}
if ([[array objectAtIndex:row] isEqual:#"Annat"]) {
enjoy.radInt = 3;
}
}

how to add 5 different custom cells in tableView

I want to show different data from web in my tableview but I am not getting how to show them in separate cells in one section of a table can any one help me to show
in one cell
cell.textLabel.text=app.i_name;
in second cell
cell.textLabel.text=app.i_phone;
in third cell
cell.textLabel.text=app.i_hours;
in forth cell
cell.textLabel.text=app.i_address;
in fifth cell
cell.textLabel.text=app.i_email;
my cell for row at index is as
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Single Cell";
SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"SingleCell" bundle:nil];
cell = (SingleCell *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:[indexPath row]];
//cell.namelbl.text=application.application_name;
return cell;
}
Try this code :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Single Cell";
SingleCell *cell =(SingleCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"SingleCell" bundle:nil];
cell = (SingleCell *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:[indexPath row]];
//cell.namelbl.text=application.application_name;
if (indexPath.row == 0)
{
cell.textLabel.text=application.i_name;
}
else if (indexPath.row == 1)
{
cell.textLabel.text = application.i_iphone;
}
else if (indexPath.row == 2)
{
cell.textLabel.text = application.i_hours;
}
else if (indexPath.row == 3)
{
cell.textLabel.text = application.i_address;
}
else
{
cell.textLabel.text = application.i_email;
}
return cell;
}
Hope this answer will help. Cheers
i solved this question by doing this code thanks for all giving suggestion
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CellForInfo";
CellForInfo *cell =(CellForInfo *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:#"CellForInfo" bundle:nil];
cell = (CellForInfo *) c.view;
//[c release];
}
appDC * application = [dataArray objectAtIndex:0];
if (indexPath.row == 0)
{
cell.lblinfo.text=application.i_name;
}
if (indexPath.row == 1)
{
cell.lblinfo.text = application.i_phone;
}
if (indexPath.row == 2)
{
cell.lblinfo.text = application.i_hours;
}
if (indexPath.row == 3)
{
cell.lblinfo.text = application.i_address;
}
if (indexPath.row == 4)
{
cell.lblinfo.text = application.i_email;
}
return cell;
}
IKQ's code example should work. But I suggest to try my TableKit library. This way the code will be more clear and elegant:
- (void)viewDidLoad
{
[super viewDidLoad];
TKStaticCell* nameCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Name" detailText:app.i_name];
TKStaticCell* phoneCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Phone" detailText:app.i_phone];
TKStaticCell* hoursCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Hours" detailText:app.i_hours];
TKStaticCell* addressCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"Address" detailText:app.i_address];
TKStaticCell* emailCell = [TKStaticCell cellWithStyle:UITableViewCellStyleValue1 text:#"email" detailText:app.i_email];
TKSection* section = [TKSection sectionWithCells:nameCell, phoneCell, hoursCell, addressCell, emailCell, nil];
self.sections = [NSArray arrayWithObject:section];
}
Also the library allows to define custom cell instead of TKStaticCell.
You can use this code for short
CellForInfo * cellForInfo = (CellForInfo *)[tableView dequeueReusableCellWithIdentifier:nil];
if (cellForInfo ==nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CellForInfo" owner:self options:nil];
cellForInfo = [nib objectAtIndex:0];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self tableInfo];
}
- (void) tableInfo
{
NSArray *keysArray = #[#"CampaignsName",#"BusinessName",#"BusinessType",#"CampaignsType",#"Distance",#"Daysleft",#"CampaignImage",];
NSArray *valuesArray1 =[NSArray arrayWithObjects:#"5 % OFF ",#"Coffe Shop",#"1",#"1",#"0.10 Miles",#"5 days Left",#"b2.png", nil];
NSArray *valuesArray2 = [NSArray arrayWithObjects:#"win $2 for you & charity ",#"Red Tommato",#"2",#"2",#"20 Miles",#"2 days Left",#"b1.png", nil];
NSArray *valuesArray3 = [NSArray arrayWithObjects:#"Buy dogs food & get a one more",#"Pet Care",#"3",#"3", #"30 Miles",#"10 days Left",#"b2.png", nil];
NSArray *valuesArray4 =[NSArray arrayWithObjects:#"win $2 for you & charity ",#"Red Tommato",#"1",#"1",#"0.10 Miles",#"7 days Left",#"b2.png", nil];
NSDictionary *dict1 = [NSDictionary dictionaryWithObjects:valuesArray1 forKeys:keysArray];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjects:valuesArray2 forKeys:keysArray];
NSDictionary *dict3 = [NSDictionary dictionaryWithObjects:valuesArray3 forKeys:keysArray];
NSDictionary *dict4 = [NSDictionary dictionaryWithObjects:valuesArray4 forKeys:keysArray];
self.tableArray = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,dict4,dict3,dict1,dict4,dict2,nil];
NSLog(#"Array %#",tableArray);
[self.tableObj reloadData];
}
#pragma mark table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableCustomView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
- (UITableViewCell *)tableCustomView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *mainCell ;
static NSString *CellIdentifier1 = #"CustomCellIdentifier";
static NSString *CellIdentifier2 = #"CustomCellIdentifier2";
if (indexPath.row % 2 != 0)
{
CustomCell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell2 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell2" owner:self options:nil];
cell2 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell2.CampaignsNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsName"]];
cell2.BusinessNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessName"]];
cell2.DistanceLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Distance"]];
cell2.DaysleftLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Daysleft"]];
cell2.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessType"]] integerValue];
NSLog(#": %d",businessType);
switch (businessType)
{
case 1:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"RETL#2x.png"];
break;
case 2:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"BTY.png"];
break;
case 3:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t3.png"];
break;
case 2:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t2.png"];
break;
case 3:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
mainCell = cell2 ;
}
else
{
CustomCell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell1" owner:self options:nil];
cell1 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell1.CampaignsNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsName"]];
cell1.BusinessNameLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessName"]];
cell1.DistanceLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Distance"]];
cell1.DaysleftLbl.text = [NSString stringWithFormat:#"%#",[object valueForKey:#"Daysleft"]];
cell1.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"BusinessType"]] integerValue];
NSLog(#": %d",businessType);
switch (businessType)
{
case 1:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"RETL#2x.png"];
break;
case 2:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"BTY.png"];
break;
case 3:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:#"%#",[object valueForKey:#"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t3.png"];
break;
case 2:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t2.png"];
break;
case 3:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:#"t1.png"];
break;
default:
break;
}
mainCell = cell1 ;
}
return mainCell;
NSLog(#"Index Path is :%d %d", indexPath.section,indexPath.row);
}

Incorrect updating content of UITableView

I have TableView which number of rows depends on the number of NSStrings in NSMutableArray friendsNames.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return friendsNames.count + 1;
}
Also each row displays that NSString at the respective index of friendsNames. Everything seems to be very simple. But when i remove a string from friendsNames and use reloadData method then weird thing happens: UITableView removes LAST row, not the row with the string which was just removed from friendsNames. Could you please explain me what's going on and what should i do to fix it?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *MyIdentifier = [NSString stringWithFormat:#"MyIdentifier %i", indexPath.row];
MyTableCell *cell = (MyTableCell *)[friendsList dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
//create columns
for (int i = 0;i < 6;i++)
[cell.contentView addSubview:[self createGrid:i :indexPath]];
}
return cell;
}
and here is the method which creates columns.it's being called from cellForRowAtIndexPath and it's pretty ugly
- (UILabel *)createGrid:(int)columnIndex :(NSIndexPath *)indexPath
{
CGFloat widths [6] = {35.0,62.0,35.0,35.0,35.0,35.0};//two arrays holding widths of the columns and points where left sides begin
CGFloat leftSides [6] = {0.0,35.0,97.0,132.0,167.0,202.0};
NSArray *titles = [[[NSArray alloc] initWithObjects:#"Status",#"ID",#"Wins",#"Losses",#"Withdrawls",#"Win %", nil] autorelease];
UILabel *columnLabel = [[[UILabel alloc] initWithFrame:CGRectMake(leftSides[columnIndex],0.0,widths[columnIndex], friendsList.rowHeight)] autorelease];
if (indexPath.row == 0)
columnLabel.text = [titles objectAtIndex:columnIndex];
else
{
switch (columnIndex)
{
case 0:
{
BOOL isOnline = [[[receivedUsers objectForKey:[friendsNames objectAtIndex:indexPath.row - 1]] objectAtIndex:0] boolValue];
columnLabel.text = isOnline ?#"On" :#"Off";
}
break;
case 1:
columnLabel.text = [friendsNames objectAtIndex:indexPath.row - 1];
break;
case 2:
columnLabel.text = [NSString stringWithFormat:#"%i",[[[receivedUsers objectForKey:[friendsNames objectAtIndex:indexPath.row - 1]] objectAtIndex:1] intValue] ];
break;
case 3:
columnLabel.text = [NSString stringWithFormat:#"%i",[[[receivedUsers objectForKey:[friendsNames objectAtIndex:indexPath.row - 1]] objectAtIndex:2] intValue] ];
break;
case 4:
columnLabel.text = [NSString stringWithFormat:#"%i",[[[receivedUsers objectForKey:[friendsNames objectAtIndex:indexPath.row - 1]] objectAtIndex:3] intValue] ];
break;
case 5:
columnLabel.text = [NSString stringWithFormat:#"%f",[[[receivedUsers objectForKey:[friendsNames objectAtIndex:indexPath.row - 1]] objectAtIndex:4] floatValue] ];
break;
}
}
columnLabel.layer.borderColor = [[UIColor blackColor] CGColor];
columnLabel.layer.borderWidth = 1.0;
columnLabel.font = [UIFont systemFontOfSize:8.0];
columnLabel.textAlignment = UITextAlignmentCenter;
columnLabel.textColor = [UIColor blackColor];
columnLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
return columnLabel;
}
It's a reusable cell problem. Just change your code like that:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *myIdentifier = [NSString stringWithFormat:#"MyIdentifier %i", indexPath.row];
MyTableCell *cell = (MyTableCell *)[friendsList dequeueReusableCellWithIdentifier:myIdentifier];
if (cell == nil) {
//Create a new cell
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:myIdentifier] autorelease];
}
//Configure the cell
//Remove all columns
for(UIVIew *subview in cell.contentView.subviews) {
[subview removeFromSuperview];
}
//Create columns
for (int i = 0;i < 6;i++) {
[cell.contentView addSubview:[self createGrid:i :indexPath]];
}
return cell;
}

Weird behavior of iPhone tableview not occurring on iPad

I have build a grouped tableview with 2 sections.
There always have to be 1 selection in each of the sections, and there can't be more.
This is working rock steady when testing on the iPad.
I recently started developing the xib for the iPhone version.
Now things start getting weird. When scrolling the selections fly all over the place, disappears, and sometimes there are 4 selections in a section.
The exact same code is working flawlessly on the iPad.
Is there any known bugs that might make this occur?
UPDATED WITH CODE:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:#"Baskerville", #"Palatino", #"Times New Roman", #"Verdana", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:#"Countries"];
NSArray *countriesLivedInArray = [NSArray arrayWithObjects:#"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", #"My Text", nil];
NSDictionary *countriesLivedInDict = [NSDictionary dictionaryWithObject:countriesLivedInArray forKey:#"Countries"];
[listOfItems addObject:countriesToLiveInDict];
[listOfItems addObject:countriesLivedInDict];
//Set the title
self.navigationItem.title = #"Countries";
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
//SET Font
NSString *neverOpendFonts1 = [prefs objectForKey:#"neverOpendFonts1"];
if (![neverOpendFonts1 isEqualToString:#"1"]) {
lastIndexPath1 = [NSIndexPath indexPathForRow:1 inSection:0];
UITableViewCell *newCell = [myTableView cellForRowAtIndexPath:lastIndexPath1];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
NSString *lastIndexPathString1 = [NSString stringWithFormat:#"1"];
[prefs setObject:lastIndexPathString1 forKey:#"lastIndexPath1"];
NSString *fontName = [NSString stringWithFormat:#"Palatino"];
[prefs setObject:fontName forKey:#"fontName"];
neverOpendFonts1 = [NSString stringWithFormat:#"1"];
[prefs setObject:neverOpendFonts1 forKey:#"neverOpendFonts1"];
[prefs synchronize];
}
else
{
NSInteger row = [[prefs objectForKey:#"lastIndexPath1"] intValue];
lastIndexPath1 = [NSIndexPath indexPathForRow:row inSection:0];
UITableViewCell *newCell = [myTableView cellForRowAtIndexPath:lastIndexPath1];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
//SET Font SIZE
NSString *neverOpendFonts2 = [prefs objectForKey:#"neverOpendFonts2"];
if (![neverOpendFonts2 isEqualToString:#"1"]) {
lastIndexPath2 =[NSIndexPath indexPathForRow:2 inSection:1];
UITableViewCell *newCell = [myTableView cellForRowAtIndexPath:lastIndexPath2];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
NSString *lastIndexPathString2 = [NSString stringWithFormat:#"2"];
[prefs setObject:lastIndexPathString2 forKey:#"lastIndexPath2"];
NSString *fontSize = [NSString stringWithFormat:#"24.0"];
[prefs setObject:fontSize forKey:#"fontSize"];
neverOpendFonts2 = [NSString stringWithFormat:#"1"];
[prefs setObject:neverOpendFonts2 forKey:#"neverOpendFonts2"];
[prefs synchronize];
}
else
{
NSInteger row2 = [[prefs objectForKey:#"lastIndexPath2"] intValue];
lastIndexPath2 = [NSIndexPath indexPathForRow:row2 inSection:1];
UITableViewCell *newCell2 = [myTableView cellForRowAtIndexPath:lastIndexPath2];
newCell2.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//Number of rows it should expect should be based on the section
NSDictionary *dictionary = [listOfItems objectAtIndex:section];
NSArray *array = [dictionary objectForKey:#"Countries"];
return [array count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [listOfItems count];
}
- (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];
}
// Set up the cell...
//First get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:#"Countries"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
if (indexPath.section == 0)
{
switch (indexPath.row) {
case 0:
{
cell.textLabel.font = [UIFont fontWithName:#"Baskerville" size:24];
}
break;
case 1:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:24];
}
break;
case 2:
{
cell.textLabel.font = [UIFont fontWithName:#"Times New Roman" size:24];
}
break;
case 3:
{
cell.textLabel.font = [UIFont fontWithName:#"Verdana" size:24];
}
break;
}
}
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:16];
}
break;
case 1:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:20];
}
break;
case 2:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:24];
}
break;
case 3:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:28];
}
break;
case 4:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:32];
}
break;
case 5:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:36];
}
break;
case 6:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:40];
}
break;
case 7:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:44];
}
break;
case 8:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:48];
}
break;
case 9:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:52];
}
break;
case 10:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:56];
}
break;
case 11:
{
cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:60];
}
break;
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// CGFloat result;
if (indexPath.section == 0)
{
return 50;
}
if (indexPath.section == 1) {
switch (indexPath.row) {
case 0:
{
return 50;
}
break;
case 1:
{
return 50;
}
break;
case 2:
{
return 50;
}
break;
case 3:
{
return 50;
}
break;
case 4:
{
return 50;
}
break;
case 5:
{
return 50;
}
break;
case 6:
{
return 50;
}
break;
case 7:
{
return 54;
}
break;
case 8:
{
return 58;
}
break;
case 9:
{
return 62;
}
break;
case 10:
{
return 66;
}
break;
case 11:
{
return 70;
}
break;
}
}
return 50;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 0) {
return #"Font";
}
if (section == 1) {
return #"Font Size";
}
else if (!section == 0 || !section == 1) {
return #"Text";
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
NSInteger newRow = [indexPath row];
if (indexPath.section == 0) {
NSString *fontName;
switch (indexPath.row) {
case 0:
{
fontName = [NSString stringWithFormat:#"Baskerville"];
}
break;
case 1:
{
fontName = [NSString stringWithFormat:#"Palatino"];
}
break;
case 2:
{
fontName = [NSString stringWithFormat:#"Times New Roman"];
}
break;
case 3:
{
fontName = [NSString stringWithFormat:#"Verdana"];
}
break;
}
NSInteger oldRow = (lastIndexPath1 != nil) ? [lastIndexPath1 row] : -1;
if(newRow != oldRow)
{
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath1];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath1 = indexPath;
}
NSInteger lastRow = lastIndexPath1.row;
NSString *lastIndexPathString = [NSString stringWithFormat:#"%i", lastRow];
[prefs setObject:lastIndexPathString forKey:#"lastIndexPath1"];
[prefs setObject:fontName forKey:#"fontName"];
[prefs synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
if (indexPath.section == 1) {
NSString *fontSize;
switch (indexPath.row) {
case 0:
{
// cell.textLabel.font = [UIFont fontWithName:#"Palatino" size:16];
fontSize = [NSString stringWithFormat:#"16.0"];
// UITableViewCell *newCell =[tableView cellForRowAtIndexPath:indexPath];
// newCell = [tableView cellForRowAtIndexPath:indexPath];
// newCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
break;
case 1:
{
fontSize = [NSString stringWithFormat:#"20.0"];
}
break;
case 2:
{
fontSize = [NSString stringWithFormat:#"24.0"];
}
break;
case 3:
{
fontSize = [NSString stringWithFormat:#"28.0"];
}
break;
case 4:
{
fontSize = [NSString stringWithFormat:#"32.0"];
}
break;
case 5:
{
fontSize = [NSString stringWithFormat:#"36.0"];
}
break;
case 6:
{
fontSize = [NSString stringWithFormat:#"40.0"];
}
break;
case 7:
{
fontSize = [NSString stringWithFormat:#"44.0"];
}
break;
case 8:
{
fontSize = [NSString stringWithFormat:#"48.0"];
}
break;
case 9:
{
fontSize = [NSString stringWithFormat:#"52.0"];
}
break;
case 10:
{
fontSize = [NSString stringWithFormat:#"56.0"];
}
break;
case 11:
{
fontSize = [NSString stringWithFormat:#"60.0"];
}
break;
}
NSInteger oldRow = (lastIndexPath2 != nil) ? [lastIndexPath2 row] : -1;
if(newRow != oldRow)
{
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath2];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath2 = indexPath;
}
NSInteger lastRow2 = lastIndexPath2.row;
NSString *lastIndexPathString2 = [NSString stringWithFormat:#"%i", lastRow2];
[prefs setObject:lastIndexPathString2 forKey:#"lastIndexPath2"];
//NSString *lastIndexPathString = [NSString stringWithFormat:#"#%", lastIndexPath2];
//[prefs setObject:lastIndexPathString forKey:#"lastIndexPath2"];
[prefs setObject:fontSize forKey:#"fontSize"];
[prefs synchronize];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
TSolved the problem... Got my answer on iphonedevsdk.com...
I added
if([self.lastIndexPath1 isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
to the cellForRowAtIndexPath
and added
if(self.lastIndexPath1)
{
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:self.lastIndexPath1];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.lastIndexPath1 = indexPath;
}
to didSelectRowAtIndexPath...
I removed the old `/*
NSInteger oldRow = (lastIndexPath1 != nil) ? [lastIndexPath1 row] : -1;
if(newRow != oldRow)
{
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath1];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath1 = indexPath;
}
*/`
from didSelectRow, and now everything works perfectly...