I am passing NSMutableArray to another a tableview and I want to show it in the table view. My NSMutableArray is as follows
2017-02-07 18:32:24.086 krib[13753:2978659] (
"Balcony.png",
"Utilities Included.png",
"Air-conditioning.png",
"Stove.png",
"WiFi Included.png",
"Queen Bed.png",
"Dining Table.png",
"Washing Machine.png",
"Dryer.png",
"Sofa.png",
"TV.png",
"Curtains.png",
"Refrigerator.png",
"Water Heater.png",
"Microwave Oven.png"
)
I send data as,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"segue"]) {
MZFormSheetPresentationViewControllerSegue *presentationSegue = (id)segue;
presentationSegue.formSheetPresentationController.presentationController.shouldApplyBackgroundBlurEffect = YES;
UINavigationController *navigationController = (id)presentationSegue.formSheetPresentationController.contentViewController;
AmennitiesTableTableViewController *presentedViewController = [navigationController.viewControllers firstObject];
// presentedViewController.textFieldBecomeFirstResponder = YES;
presentedViewController.passingString = facilities;
}
and receive data in table view controller,
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Close" style:UIBarButtonItemStylePlain target:self action:#selector(close)];
NSLog(#"%#",self.passingString);
[self.tableView reloadData];
}
I tried showing the mutable array as follows,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"facilitiesCell";
AmenitiesTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.facilitylbl.text = [self.passingString objectAtIndex:indexPath.row];
// Configure the cell...
return cell;
}
But I am not understanding what exactly i am missing to Populate data on the tableview.
I think you are missing to set tableview delegate & datasource.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Close" style:UIBarButtonItemStylePlain target:self action:#selector(close)];
[self.myTable setDelegate:self];
[self.myTable setDataSource:self];
NSLog(#"%#",self.passingString);
[self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.passingString.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"facilitiesCell";
AmenitiesTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(self.passingString.count > 0){
cell.facilitylbl.text = [self.passingString objectAtIndex:indexPath.row];
}
// Configure the cell...
return cell;
}
Related
I'm learning how to make a contact using TableView and navigation controller. I have done the first view page with some cells, but I have some problem with showing the cells on the detail view page of each cell from first view.
when tap the Group A, Group B, Group C on first view page, it goes to the detail view of each cell, it should show cells named A1 A2 A3, B1 B2 B3 or C1 C2 C3 according to my code on detail view page. but it display nothing.
Hope someone can give me some advises, thank you so much!
FirstViewController.m
#implementation FirstViewController
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSections(NSInteger)section{
return [self.contactArray count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *Celldentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier];
if (cell == NULL) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier];
}
cell.textLabel.text = [self.contactArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.myTableView = [self.contactArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"To Second View Segue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"To the second view"]){
NSIndexPath *indexpath = [self.myTableView indexPathForSelectedRow];
self.contactArray = [self.contactArray objectAtIndex:indexpath.row];
SecondViewController *vc = segue.destinationViewController;
vc.memberName = [self.contactArray objectAtIndex:indexpath.row];
vc.title = vc.memberName;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.contactArray = [[NSMutableArray alloc]initWithObjects:#"Group A",#"Group B",#"Group C", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
SecondViewController.m
#implementation SecondViewController{
NSArray *groupA;
NSArray *groupB;
NSArray *groupC;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if([self.memberName isEqualToString:#"groupA"]){
return [groupA count];
}
else if([self.memberName isEqualToString:#"groupB"]){
return [groupB count];
}
else if([self.memberName isEqualToString:#"groupC"]){
return [groupC count];
}
return 0;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *Celldentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier];
if (cell == NULL) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier];
}
if([self.memberName isEqualToString:#"groupA"]){
cell.textLabel.text = [groupA objectAtIndex:indexPath.row];
}
if([self.memberName isEqualToString:#"groupB"]){
cell.textLabel.text = [groupB objectAtIndex:indexPath.row];
}
if([self.memberName isEqualToString:#"groupC"]){
cell.textLabel.text = [groupC objectAtIndex:indexPath.row];
}
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
groupA = [NSArray arrayWithObjects:#"A1",#"A2",#"A3",nil];
groupB = [NSArray arrayWithObjects:#"B1",#"B2",#"B3",nil];
groupC = [NSArray arrayWithObjects:#"C1",#"C2",#"C3",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
first view
detail view but nothing displayed
Have you set the delegate and datasource of tableview?
If Yes, check if the datasource methods (numberOfRowsInSection:) are called after you do
groupA = [NSArray arrayWithObjects:#"A1",#"A2",#"A3",nil]; in viewDidLoad method.
Please guide me in passing data. My storyboard contains two tabbars. In first view I put two buttons by selector in navigationbar that add and remove objects from bookmark. It's not a problem until here. When I change my tabbar to show updated bookmark database in tableview I see duplicated object in rows. I used
- (void)viewWillAppear:(BOOL)animated
and
[tableview reloadData];
but still it shows duplicated object. this is my second class code to show updated data
#implementation BookmarkViewController
#synthesize data , tableData , tblView ;
- (void)viewDidLoad{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
sql = [[SQLiteManager alloc]initWithDatabaseNamed:#"datadic.db"];
bookmarkQuery = #"SELECT EN FROM table WHERE BOOKMARK IS 1";
res = [sql getRowsForQuery:bookmarkQuery];
tableData = [[NSMutableArray alloc]initWithArray:[res valueForKey:#"EN"]];
NSLog(#"%#" , tableData);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
indexRow = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
tblView = [[UITableView alloc]init];
static NSString *myIdentifier = #"CELL";
myCell = [tblView dequeueReusableCellWithIdentifier:myIdentifier];
if (myCell == nil) {
myCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: myIdentifier];
}
[tblView reloadData];
myCell.textLabel.textColor = [UIColor blueColor];
myCell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return myCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [tableData count];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[tableData removeObjectAtIndex:indexPath.row];
[tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:YES];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
#end
The problem is most likely that you are instantiating a spare copy of UITableView every time [cellForRowAtIndexPath] is called. You call both [reloadData] as well as [deleteRowsAtIndexPaths] on this copy, which doesn't do anything.
Try this revised code (I'm assuming BookmarkViewController is a subclass of UITableViewController):
#implementation BookmarkViewController
#synthesize data , tableData , tblView ;
- (void)viewDidLoad{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
sql = [[SQLiteManager alloc]initWithDatabaseNamed:#"datadic.db"];
bookmarkQuery = #"SELECT EN FROM table WHERE BOOKMARK IS 1";
res = [sql getRowsForQuery:bookmarkQuery];
tableData = [[NSMutableArray alloc]initWithArray:[res valueForKey:#"EN"]];
NSLog(#"%#" , tableData);
[tblView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
indexRow = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
static NSString *myIdentifier = #"CELL";
myCell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
if (myCell == nil) {
myCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: myIdentifier];
}
myCell.textLabel.textColor = [UIColor blueColor];
myCell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return myCell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [tableData count];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[tableData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:YES];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
#end
I have got an issue with getting Delete button on Edit one clicks. The problem is being that it doesn't appear at all. My code is below and it works for swiping across a cell... Thank you in advance for the help!
#import "ViewController.h"
#interface ViewController ()
#property (strong) NSArray *lessons;
#end
static NSString *identifier = #"Cell";
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.lessons = #[
#"Computer Science",
#"Math",
#"Chemistry"
];
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:identifier];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.lessons.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = self.lessons[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
#end
Once I pressed Edit button.
This appears when I swiped across the cell.
hear above coding see that its really useful for that.
- (HelloController *) init
{
if (!(self = [super init])) return self;
self.title = #"Table Edits";
// Initialize the table titles, so they can be edited over time
tableTitles = [[NSMutableArray alloc] init];
ithTitle = NCELLS;
for (int i = 1; i <= NCELLS; i++)
[tableTitles addObject:[NSString stringWithFormat:#"Table Cell #%d", i]];
return self;
}
#pragma mark UITableViewDataSource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView :(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableTitles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"any-cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"any-cell"] autorelease];
}
cell.text = [tableTitles objectAtIndex:[indexPath row]];
// cell.editingStyle = UITableViewCellEditingStyleDelete; // now read-only and no longer needed
return cell;
}
- (void) add
{
[tableTitles addObject:[NSString stringWithFormat:#"Table Cell #%d", ++ithTitle]];
[self.tableView reloadData];
}
#pragma mark UITableViewDelegateMethods
- (void) deselect
{
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
// Respond to user selection
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
{
printf("User selected row %d\n", [newIndexPath row] + 1);
[self performSelector:#selector(deselect) withObject:nil afterDelay:0.5f];
}
-(void)leaveEditMode
{
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:#"Edit"
style:UIBarButtonItemStylePlain
target:self
action:#selector(enterEditMode)] autorelease];
[self.tableView endUpdates];
[self.tableView setEditing:NO animated:YES];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
printf("About to delete item %d\n", [indexPath row]);
[tableTitles removeObjectAtIndex:[indexPath row]];
[tableView reloadData];
}
-(void)enterEditMode
{
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:#"Done"
style:UIBarButtonItemStylePlain
target:self
action:#selector(leaveEditMode)] autorelease];
[self.tableView setEditing:YES animated:YES];
// [self.tableView beginUpdates];
}
- (void)loadView
{
[super loadView];
// Add an add button
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:#"New"
style:UIBarButtonItemStylePlain
target:self
action:#selector(add)] autorelease];
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:#"Edit"
style:UIBarButtonItemStylePlain
target:self
action:#selector(enterEditMode)] autorelease];
}
If anyone has the same issue, then you are probably using a UITableView in a UIViewController, so it doesn't manage editions for you. When you click Edit button, you must implement TableView's editing mode AND View's editing mode manually. How have I solved that issue.
#pragma mark - Edit button listener
- (void)editButtonPressed {
if(self.editing) {
[self setEditing:NO animated:YES];
[self.tableView setEditing:NO animated:YES];
} else {
[self setEditing:YES animated:YES];
[self.tableView setEditing:YES animated:YES];
}
}
Thank you guys for commenting!
Can someone help me? I've been following along with Apple's official Objective C tutorial (the one that has us create a To Do List).
I'm stuck at the part where tapping the cell item displays/removes a checkmark. It's not happening.
Here's my implementation file if someone could take a look?
I've really tried my best to solve where I went wrong. I swear I tried my best to figure out everything on my own before posting here. Please, any help would be greatly appreciated!!
Thank you!
EDIT: So i put a breakpoint in my didSelectRowAtIndexPath method. It was not triggered when I tapped a table item, so it's not getting called when I tap items, right? Where do I look next?
//
// ToDoListTableViewController.m
// ToDoList
//
// Created by Kevin Zagala on 9/1/14.
// Copyright (c) 2014 Kevin Zagala. All rights reserved.
//
#import "ToDoListTableViewController.h"
#import "ToDoItem.h"
#interface ToDoListTableViewController ()
#property NSMutableArray *toDoItems;
#end
#implementation ToDoListTableViewController
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
}
- (void)loadInitialData {
ToDoItem *item1 = [[ToDoItem alloc] init];
item1.itemName = #"Buy milk";
[self.toDoItems addObject:item1];
ToDoItem *item2 = [[ToDoItem alloc] init];
item2.itemName = #"Buy eggs";
[self.toDoItems addObject:item2];
ToDoItem *item3 = [[ToDoItem alloc] init];
item3.itemName = #"Read a book";
[self.toDoItems addObject:item3];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.toDoItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableview:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
[tableView reloadRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
#end
try this ..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
try reloading whole tableview,
what u are doing should work, i tested your code by putting a dummy object with boolean value, it worked for me,
Note Both reloading the whole tableview and reloading the selected cell will work, only u are setting the correct boolean value
- (void)tableview:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
// [tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone]; //comment this
[tableView reloadData]; //add this
}
here i have made a table class in which i have a list of 120 words, now i have to select minimum ten rows of the table for further precision.. please any one can guide me that how can i select more than 10 rows from table and save these value in specific array or somewhere else.. please help me out of it.
#implementation tableview
NSArray *myArray ;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myArray = [NSArray arrayWithObjects:
#"ad (a-d)",.......,Nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (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];
}
cell.textLabel.text = [myArray objectAtIndex:indexPath.row]; //=#"ASDF" works.
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
#end
For multiple cell selection in your table add this code inside didSelectRowAtIndexPath: method. For saving selection values, create an iVar NSMutableArray and add the newly selected object inside didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
One quick idea that come into mind is, as soon as you select a row/cell, save the values in a collection object (array, dictionary), and keep on adding.
Delete from the collection if you deselect the row/cell.