UITableView cell empty when called recursively - ios

I'm trying to use recursive table view but when I click to any cell and second UITableView appears (created by tableView:didSelectRowAtIndexPath:), there are just empty rows without any text.
Can somebody help please ?
#implementation RSTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self.tableView registerClass:[RSCell class] forCellReuseIdentifier:#"bbaCell"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.array = [NSMutableArray arrayWithObjects:#"1",#"2",#"3", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain];
rsTableView.tableView.delegate = self;
[self.navigationController pushViewController:rsTableView animated:TRUE];
[tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"bbaCell";
RSCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.label1.text = [self.array objectAtIndex:indexPath.row];
cell.label2.text = [self.array objectAtIndex:indexPath.row];
return cell;
}
#end

A. [self.navigationController pushViewController:rsTableView animated:TRUE] is wrong, there's no such thing as TRUE, there's only YES.
B. I feel like you're doing something very wrong but anyway, you method should be the following:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RSTableViewController *rsTableView = [[RSTableViewController alloc] initWithStyle:UITableViewStylePlain];
// each rs table view instance is it's own delegate and datasource
rsTableView.tableView.delegate = rsTableView;
// you forgot to add this line:
rsTableView.tableView.dataSource = rsTableView;
[self.navigationController pushViewController:rsTableView animated:YES];
// what's this line for ?? the new ViewController will automatically call all the necessary methods. please remove it.
[tableView reloadData];
}
please check the syntax, and secondly, what's RSTableViewController base ViewController ?? is it UITableViewController ??
make sure you're setting the delegate and datasource properly.

Related

how link row in tableView to a segue

I have two viewControllers, ViewController and TableViewController. the ViewController has a button, when pressed the TableViewController will start. the TableViewContoller contains 5 rows.
what I am trying to do is, when I press only the even rows I should go back to ViewController. To solve this problem, we can use unwindSegue, but I do not know how to have the segue respond to the even rows in the table.
please let me know how to make a row in the table linked to the segue
below is the code for TableViewController
code:
#import "TableViewController.h"
#interface TableViewController ()
#property NSArray *tableData;
#end
#implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableData = [NSArray arrayWithObjects:#"Android",
#"iOS",
#"swift",
#"objective-c",
#"openCV",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section {
return [self.tableData count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:#"images.jpg"];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
NSLog(#"%li", indexPath.row);
NSLog(#"%#", [self.tableData objectAtIndex:indexPath.row]);
}
#end
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
if(indexPath.row % 2 == 0) {
// Even row...
}
}

Recreate a uitableview section dynamically on a uibutton`s click

I need to recreate a UITableView section on a UIButton click. Here is an example for this.
AND in button click it should be created like this.
But i am not able to implement this .
Please Help.
I am just creating a simple UITableView with a textLabel.
Code For cellForRowAtIndexPath is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
Create a integer variable index and property for tableview in .h
#property UITableView *tableView;
Then in -(void)viewDidLoad set index=0;
Now, write a method which is get called when you tap on add button
-(void)newTableView
{
tableView = [UITableView alloc] initWithFrame:CGRectMake(x,y+height*index,width,height)];
//other code related to table
tableView.tag = ++index;
[self.view addSubview:tableView];
}
Use tag in delegate methods
Edit: As you requested to add new section in Table View instead of new table view
You have to first create table view of grouped style
tableView = [UITableView alloc] initWithFrame:(CGRect)frame style:UITableViewStyleGrouped];
Now, When you hit on that add button call a method
-(void)newSection
{
count++;
[tableView reloadData];
}
Then, you have to implement this delegate methods for grouped table view
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return #"title";
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
//same as your previous code
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//same as your previous code
}
//
// ViewController.m
// DynamicNewSections
//
// Created by J Pulikkottil on 14/07/15.
// Copyright (c) 2015 J Pulikkottil. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#property(nonatomic) NSMutableArray *arrayData;
#property (strong, nonatomic) IBOutlet UITableView *tableViewTest;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.arrayData = [NSMutableArray array];
//section1
[self addSectionArray];
}
- (IBAction)addSection:(UIButton *)sender {
[self addSectionArray];
[self.tableViewTest reloadData];
}
- (void) addSectionArray{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:#"Height",#"label", #"", #"value", nil];
NSArray *arraysection = [NSArray arrayWithObjects:dict, nil];
[self.arrayData addObject:arraysection];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableViewTest.frame.size.width, 45)];
view.backgroundColor = [UIColor yellowColor];
return view;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return [self.arrayData count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [[self.arrayData objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CellDetails" forIndexPath:indexPath];
NSArray *arraysection = [self.arrayData objectAtIndex:indexPath.section];
NSDictionary *dict = [arraysection objectAtIndex:indexPath.row];
cell.textLabel.text = [dict valueForKey:#"label"];
cell.detailTextLabel.text = [dict valueForKey:#"value"];
return cell;
}
#end
Try this:
Just have a property (e.g. numberOfSections)
Set it to 1 in viewDidLoad
In the numberOfSectionsInTableView: return self.numberOfSections;
In the IBAction of your UIButton add this code:
self.numberOfSections++;
[self.tableView beginUpdates];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:self.numberOfSections-1]
withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];

Trying to load UIViewController after click of item in TableViewController

I feel like this is a fairly easy question, but I've tried for hours and can't seem to get it. I'm trying to create an app that calculates different equations that are critical to my job. Essentially, I've grouped the calculations into categories using nested TableViewControllers. This part works.
The part I am trying to figure out is how to push to a UIViewController so I can actually have the user enter data to do the calculations. For some reason I can't seem to get it to work. I am using Xcode 5 and am using Storyboards.
Really sorry for the long post. I've also included a screenshot of the storyboard at the following link: http://imgur.com/0oSxsR1
code below:
Root TableViewController Code (RootTableViewController.m)
#import "RootTableViewController.h"
#import "calculatorTableViewController.h"
#interface RootTableViewController ()
#end
#implementation RootTableViewController{
NSArray *calculatorOptions;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
calculatorOptions = [NSArray arrayWithObjects: #"General", #"Digital", #"Print", #"Television", nil];
}
- (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 [calculatorOptions count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"CalculatorCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [calculatorOptions objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"calculatorDetails"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
calculatorTableViewController *destViewController = segue.destinationViewController;
destViewController.calculationType = [calculatorOptions objectAtIndex:indexPath.row];
destViewController.title = destViewController.calculationType;
}
}
#end
Secondary TableViewController.h file (calculatorTableViewController.h)
#import <UIKit/UIKit.h>
#interface calculatorTableViewController : UITableViewController
#property (nonatomic, strong) NSString *calculationType;
#end
Secondary TableViewController.m file (calculatorTableViewController.m)
#import "calculatorTableViewController.h"
#import "CalculateGrpsHaveRF.h"
#interface calculatorTableViewController ()
#end
#implementation calculatorTableViewController{
NSArray *general;
NSArray *digital;
NSArray *print;
NSArray *television;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
general = [NSArray arrayWithObjects:#"Calculate GRPs (Have R & F)", #"Calculate Reach (Have GRPs & F)", #"Calculate Frequency (Have GRPs & R)", #"CPM to CPP", #"CPP to CPM", nil];
digital = [NSArray arrayWithObjects:#"Calculate Impressions (Have cost & CPM)", #"Calculate CPM (Have cost & impressions)", #"Calculate Cost (Have CPM and Impressions)", #"Calculate ASF", #"Calculate CPC/CPA/CPV", nil];
print = [NSArray arrayWithObjects:#"Calculate CPM", #"Calculate GRPs", #"Calculate CPP", nil];
television = [NSArray arrayWithObjects:#"Universe Estimates", #"Calculate GRPs", #"Calculate Spots", #"Calculate Average Rating", #"Calculate Total Impressions", #"Calculate CPP", nil];
}
- (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
{
if ([_calculationType isEqualToString:#"General"]){
return [general count];
}
else if ([_calculationType isEqualToString:#"Digital"]){
return [digital count];
}
else if ([_calculationType isEqualToString:#"Print"]){
return [print count];
}
else if ([_calculationType isEqualToString:#"Television"]){
return [television count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"Calculator2Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if ([_calculationType isEqualToString:#"General"]) {
cell.textLabel.text = [general objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Digital"]) {
cell.textLabel.text = [digital objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Print"]) {
cell.textLabel.text = [print objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Television"]) {
cell.textLabel.text = [television objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"Calculate GRPs (Have R & F)"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
CalculateGrpsHaveRF *destViewController = segue.destinationViewController;
destViewController.Title = [general objectAtIndex:indexPath.row];
#end
If I understand correctly, you want calculatorTableViewController to perform segue to next view.
//when you select a row
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//perform a segue
if (indexPath.row == 1)
{
[self performSegueWithIdentifier:#"your_segue_identifier" sender:your_sender];
}
else if (indexPath.row == 2)
{
[self performSegueWithIdentifier:#"another_segue_identifier" sender:your_sender];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//prepare your segue here
}

How to select and save multiple values from tables rows

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.

Couldn't launch self.editing mode when press Edit button in TableView

I'm trying to create an editable table in iPhone App. I have two questions.
When I press the Edit button and thus enter the editing mode, I cannot delete a row.
If there's a way to add a "add new cell" function instead of the way I did in my code? (I added a addButtonAction method.)
Here's my .h
#import <UIKit/UIKit.h>
#interface FirstViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
UITableView *table;
NSMutableArray *tableDataSource;
}
-(IBAction)addButtonAction:(id)sender;
#end
Here's the .m
#import "FirstViewController.h"
#implementation FirstViewController
- (IBAction)addButtonAction:(id)sender
{
if(tableDataSource != nil)
{
[tableDataSource addObject:#"New City"];
}
[table reloadData];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
tableDataSource = [[NSMutableArray alloc]init];
[tableDataSource addObjectsFromArray:[NSArray arrayWithObjects: #"Canada", #"United States", #"Australia", #"United Kingdom", nil]];
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 367) style:UITableViewStyleGrouped];
[table setDataSource:self];
[table setDelegate:self];
[self.view addSubview:table];
[[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(addButtonAction:)];
[[self navigationItem] setRightBarButtonItem:addButton];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self tableView] reloadData];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableDataSource 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];
}
// Configure the cell...
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [tableDataSource objectAtIndex:indexPath.row];
return cell;
}
#pragma - Enable/Disable Edit Button
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing
animated:animated];
[table setEditing:editing animated:animated];
}
#pragma - Editing Style
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
#pragma - Can Move Row
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *item = [tableDataSource objectAtIndex:fromIndexPath.row];
[tableDataSource removeObject:item];
[tableDataSource insertObject:item atIndex:toIndexPath.row];
}
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
#pragma mark - Table Title
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
return #"City";
}
else
{
return #"Nothing here";
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
//TBD....
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#end
Make sure when you delete row from tableView also to delete the object from NSArray.
This addButton I thik will work but this
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
make like this:
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
Just remove if statament...
Hope I understand your question ant this help.

Resources