assigning datasource to two tableviews in one view controller - iphone

Whats wrong in the following code?
here i am using two table views and assigning them with different data source, but its not working
-(void)viewDidLoad
{
[super viewDidLoad];
arryData = [[NSArray alloc] initWithObjects:#"MCA",#"MBA",#"BTech",#"MTech",nil];
arryData2 = [[NSArray alloc] initWithObjects:#"Objective C",#"C++",#"C#",#".net",nil];
flag=1;
myTable1.hidden=YES;
myTable2.hidden=YES;
btnOne.layer.cornerRadius=8;
btnTwo.layer.cornerRadius=8;
myTable1.layer.cornerRadius=8;
myTable2.layer.cornerRadius=8;
myTable1.delegate=self;
myTable1.dataSource=self;
myTable2.delegate=self;
myTable2.dataSource=self;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(self.myTable1=tableView)
{
return [arryData count];
}
else {
return [arryData2 count];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 20;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView==self.myTable1)
{
static NSString *CellIdentifier1 = #"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] ;
}
cell.textLabel.text = [arryData objectAtIndex:indexPath.row];
NSLog(#"1here is%i %#",indexPath.row,cell.textLabel.text);
return cell;
}
else
{
static NSString *CellIdentifier2 = #"Cell2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] ;
}
cell.textLabel.text = [arryData2 objectAtIndex:indexPath.row];
return cell;
}
}
-(IBAction)btnCategory:(id)sender
{
if (flag==1) {
flag=0;
myTable1.hidden=NO;
myTable2.hidden=YES;
}
else{
flag=1;
myTable1.hidden=YES;
myTable2.hidden=YES;
}
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
myTable1.hidden=YES;
myTable2.hidden=YES;
}
-(IBAction)btnTopic:(id)sender
{
if (flag==1) {
flag=0;
myTable2.hidden=NO;
myTable1.hidden=YES;
}
else{
flag=1;
myTable2.hidden=YES;
myTable1.hidden=YES;
}
}
</code>
when i remove datasource of mytable2 all data gets added to table1 else nothing gets loaded in none of the table.

You did mistake. See my code..
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(self.myTable1==tableView) // ----- Change here you need to write == symbol instead of = symbol
{
return [arryData count];
} else {
return [arryData2 count];
}
}

Try this,
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView==myTable1)
{
return [arryData count];
}
else {
return [arryData2 count];
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier= #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
if(myTable1==tableView)
{
cell.textLabel.text = [arryData objectAtIndex:indexPath.row];
NSLog(#"1here is%i %#",indexPath.row,cell.textLabel.text);
}
else
{
cell.textLabel.text = [arryData2 objectAtIndex:indexPath.row];
}
return cell;
}

Related

how to code to select multiple row with check mark?

I have taken UITableView. I want to use checkmark on row. When row is selected check mark should show there and when he selects check mark row then check mark should disappear.
I used following code.
In my code only I select multiple row but am able to disappear on same checkmark with selected row.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//if (cell == nil) {
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text=[[gmailList objectAtIndex:indexPath.row]valueForKey:#"Name"];
if(cell.selected)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Configure the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Uncheck the previous checked row
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell.selected)
{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selected=FALSE;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.selected=TRUE;
}
}
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath{
if ([tableView tag]==2){
self.clearCheckMark = false;
if ([tableView cellForRowAtIndexPath:indexPath].accessoryType ==UITableViewCellAccessoryCheckmark)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
else
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
self.index = [tableView indexPathsForSelectedRows];
}
return indexPath;}
Try this- You have to define a global NSMutableDict and use that dict as below
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//if (cell == nil) {
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text=[[gmailList objectAtIndex:indexPath.row]valueForKey:#"Name"];
if([[dict objectForKey:[NSString stringWithFormat:"%d",indexPath.row]] isEqualToString:#"YES"])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Configure the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Uncheck the previous checked row
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell.selected)
{
cell.accessoryType = UITableViewCellAccessoryNone;
[[dict setObject:#"NO"]] forKey:[NSString stringWithFormat:"%d",indexPath.row];
cell.selected=FALSE;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.selected=TRUE;
[[dict setObject:#"YES"]] forKey:[NSString stringWithFormat:"%d",indexPath.row];
}
}
Set NSMutableDictionary with key like "isChecked" "YES" or "NO" using below method
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
NSMutableDictionary *dic = [gmailList objectAtIndex:indexPath.row];
if([[dic valueForKey:#"isChecked"]boolValue])
{
cell.accessoryType = UITableViewCellAccessoryNone;
[dic setObject:#"NO" forKey:#"isChecked"];
cell.selected=FALSE;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[dic setObject:#"YES" forKey:#"isChecked"];
cell.selected=TRUE;
}
[self.tableView reloadData];
}

Search Results not visible

I have a table view with a search display controller. When I type a search the log shows me the search is working and filtering properly however the screen only shows "No Results". I'm using Core Data if that makes a difference.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
}
else{
return[[self.fetchedResultsController sections]count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections]objectAtIndex:section];\
return [secInfo numberOfObjects];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
static NSString *CellIdentifier = #"Cell";
if (tableView != self.tableView) {
NSLog(#"Found searchDisplayController");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSLog(#"Found regular table View");
}
// Configure the cell...
Instance *instance = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = instance.name;
}
Here are NumberOfRowsInSection and Number:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
}
else{
return[[self.fetchedResultsController sections]count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections]objectAtIndex:section];\
return [secInfo numberOfObjects];
}
Check your implementation of numberOfSectionsInTableView and numberOfRowsInSection.
In the first, you should return 1 if it's the search table view (1 section).
In numberOfRowsInSection you should also check the given tableView argument as you did in numberOfSectionsInTableView and return [searchResults count].
Shouldn't your implementation be something like :-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return 1;
}
else
{
return[[self.fetchedResultsController sections]count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(tableView == self.searchDisplayController.searchResultsTableView)
{
return [searchResults count];
}
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections]objectAtIndex:section];\
return [secInfo numberOfObjects];
}
If the number of search results is high, then I would suggest using another Fetched Results Controller instead of an array.

Plist Search of Tableview

I have Plist which is been populated on the tableview with expanded sections ..now i want to search the table..below in images you can see what is happening when I search anything.
.
just because I am searching it but need some changes in the cellforrowatindexpath for search results....
please check the code and let me know what to do for searching plist..
what should be changes for the cellforrowatindexpath and noofrowsinsection for search from plist
.
.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.mySections count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger rows = 0;
if ([self tableView:tableView canCollapseSection:section] || !(tableView == self.searchDisplayController.searchResultsTableView) )
{
if ([expandedSections containsIndex:section] )
{
NSString *key = [self.mySections objectAtIndex:section];
NSArray *dataInSection = [[self.myData objectForKey:key] objectAtIndex:0];
return [dataInSection count];
}
return 1;
} else if(tableView == self.searchDisplayController.searchResultsTableView) {
rows = [self.searchResults count];
return rows;
}
return 1;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section {
NSString *key = [self.mySections objectAtIndex:section];
return [NSString stringWithFormat:#"%#", key];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//some changes required to display plst
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
}
// Configure the cell...
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {
cell.textLabel.text = [self.searchResults objectAtIndex:indexPath.row];
}else {
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [self.mySections objectAtIndex:section];
NSDictionary *dataForSection = [[self.myData objectForKey:key] objectAtIndex:0];
NSArray *array=dataForSection.allKeys;
cell.textLabel.text = [[dataForSection allKeys] objectAtIndex:row];
cell.detailTextLabel.text=[dataForSection valueForKey:[array objectAtIndex:indexPath.row]];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
if (!indexPath.row)
{
// only first row toggles exapand/collapse
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSInteger section = indexPath.section;
BOOL currentlyExpanded = [expandedSections containsIndex:section];
NSInteger rows;
NSMutableArray *tmpArray = [NSMutableArray array];
if (currentlyExpanded)
{
rows = [self tableView:tableView numberOfRowsInSection:section];
[expandedSections removeIndex:section];
}
else
{
[expandedSections addIndex:section];
rows = [self tableView:tableView numberOfRowsInSection:section];
}
for (int i=1; i<rows; i++)
{
NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i
inSection:section];
[tmpArray addObject:tmpIndexPath];
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (currentlyExpanded)
{
[tableView deleteRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown];
}
else
{
[tableView insertRowsAtIndexPaths:tmpArray
withRowAnimation:UITableViewRowAnimationTop];
cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];
}
}
}
}
- (void)filterContentForSearchText:(NSString*)searchText
scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:#"SELF contains[cd] %#",
searchText];
self.searchResults = [self.mySections filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
UISearchBar * searchBar = [controller searchBar];
[self filterContentForSearchText:searchString scope:[[searchBar scopeButtonTitles] objectAtIndex:[searchBar selectedScopeButtonIndex]]];
return YES;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
UISearchBar * searchBar = [controller searchBar];
[self filterContentForSearchText:[searchBar text] scope:[[searchBar scopeButtonTitles] objectAtIndex:searchOption]];
return YES;
}
The search results you are using in numberOfRows should be used for numberOfSections
Since you are filtering for section title and not rows.

how to load the items in array at run time

I have three tableView one containg cateogry one containg type and other product name i want that when user selct any category the type array should be loaded at run time getting the same type of the selected category
In my example if i select category Herbicide then it should insert the contents of the
typeHerbicides in arrayType but when i load table second it does not show any values
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView ==tblSimpleTable )
return [categoryArray count];
else if(tableView==tblSimpleTableType)
return [typeArray count];
else if(tableView==tblSimpleTableProduct)
return [productArray count];
else if(tableView==tblSimpleTableOneSection)
return [categorySectionOneArray count];
else if(tableView==tblSimpleTableTypeSection)
return [typeArraySection count];
else
return [productArraySection count];
}
// Customize the appearance of table view cells.
- (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];
}
if (tableView ==tblSimpleTable ) {
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [categoryArray objectAtIndex:indexPath.row];
return cell;
}
else if (tableView==tblSimpleTableType){
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [typeArray objectAtIndex:indexPath.row];
return cell;
}
else if(tableView==tblSimpleTableProduct) {
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [productArray objectAtIndex:indexPath.row];
return cell;
}
else if(tableView==tblSimpleTableOneSection){
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [categorySectionOneArray objectAtIndex:indexPath.row];
return cell;
}
else if(tableView==tblSimpleTableTypeSection){
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [typeArraySection objectAtIndex:indexPath.row];
return cell;
}
else {
cell.textLabel.font=[UIFont fontWithName:#"Arial" size:16];
cell.textLabel.text = [productArraySection objectAtIndex:indexPath.row];
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView ==tblSimpleTable ) {
titleCategory=[categoryArray objectAtIndex:indexPath.row];
NSLog(#"This is titleCategory Selected %#",titleCategory);
NSString*test=#"Herbicides";
if([titleCategory isEqualToString:test]){
typeHerbicides=[[NSArray alloc] initWithObjects:#"ACCLAIM EXTRA",#"ILLOXAN",#"REVOLVER",nil];
typeArray=[[NSArray alloc] initWithArray:typeHerbicides copyItems:YES];
}
else {
typeArray=[[NSArray alloc] initWithObjects:#"ILLOXAN",#"REVOLVER",nil];
typeArray=[[NSArray alloc] initWithArray:typeHerbicides copyItems:YES];
}
}
else if(tableView==tblSimpleTableType)
titleType=[typeArray objectAtIndex:indexPath.row];
else if(tableView==tblSimpleTableProduct)
titleProduct=[productArray objectAtIndex:indexPath.row];
else if(tableView==tblSimpleTableOneSection)
titleSectionOneCategory=[categorySectionOneArray objectAtIndex:indexPath.row];
else if(tableView==tblSimpleTableTypeSection)
titleTypeSection=[typeArraySection objectAtIndex:indexPath.row];
else
titleProductSection=[productArraySection objectAtIndex:indexPath.row];
}
When user selects any category then in didSelectRowAtIndexPath you can initialize your typeArray based on category selected:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == tblSimpleTableType)
{
//initialize typeArray;
//Once typeArray is initialized just reload the tableview as follows:
[tblSimpleTableType reloadData];
}
}
Just try by returning the cell at last of the function only and see.

iphone table view check mark accessory problem

I have a table with 50 rows. I want to select particular rows with checkmark accessory but when i select some rows and scroll down the table then i see pre checked rows. I know that table cell are reused but i want to emit this problem what can i do about this?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// return [array count];
return 50;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[NSString stringWithFormat:#"%i",[indexPath row]];
return cell;
}
// Override to support row selection in the table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
You have to set cell.accessoryType in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
The fact is that as you have a reuse identifier, when a new cell is requested, a cell with the identifier is copied. As you have set the checkmark in the latest cell, the checkmask is copied.
You have to store the state of each cell (ie in an array) to recreate the cell with the right value.
Something like that:
BOOL values[50]; //Not the best way, but easy for the example...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[NSString stringWithFormat:#"%i",[indexPath row]];
if (value[indexPath.row]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
values[indexPath.row] = !value[indexPath.row];
if (value[indexPath.row]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
You can do it with the help of array ,take one array and each array hold a dict do this condition in array
NSMutableArray *arr = [[NSMutableArray alloc]init];
for(int i=1; i<=50;i++)
{
NSmutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setobject:[nsstring stringwithformat:#"%d",i] valueForkey:#"ID"];
[arr addobject:dict];
[dict release];
}
now rows is [arr count];
and put this check in cell appearance
NSMutabledict *dict1 = [arr objectatindex:indexpath.row];
if([[dict objectforkey:"Check"]==nil])
{
[dict setobject:[nsstring stringwithformate:#"1"] valueforkey:#"Check"];
}else
{
if([[dict objectforkey:"Check"] isequaltostring:#"1"]
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
now put below code in didselect methood
nsmutabledict *dict1 = [arr objectatindex:indexpath.row];
if([[dict objectforkey:"Check"] isequaltostring:#"1"]
{
[dict setobject:[nsstring stringwithformate:#"2"] valueforkey:#"Check"];
}
else
{
[dict setobject:[nsstring stringwithformate:#"1"] valueforkey:#"Check"];
}