I have a tableview that I am populating with JSON, but it is doubling the values that I have. I only have 2 objects, but it is putting 4 in the tableview. Can someone tell me what I am doing wrong and why I am listing 4 objects when there are only 2? I have checked the count and the data model and they both only show 2 items.
Here is my code:
//
// RootBeerTableViewController.m
// BaseApp
//
// Created by Blaine Anderson on 9/27/12.
// Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//
#import "RootBeerTableViewController.h"
#import "GlobalData.h"
#interface RootBeerTableViewController ()
#end
#implementation RootBeerTableViewController
#synthesize rootList;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
self.view = tableView;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
rootList =[[GlobalData sharedData].mRootBeers getRootBeers];
NSLog(#"RootList: %#", rootList);
// Return the number of sections.
NSLog(#"RootList count: %i", rootList.count);
return rootList.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of sections.
NSLog(#"RootList row count: %i", rootList.count);
return rootList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
rootList =[[GlobalData sharedData].mRootBeers rootBeerList];
NSLog(#"RootList Cell: %#", rootList);
RootBeers* mRootBeer = [rootList objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSLog(#"Cell Name: %#", mRootBeer.name);
// Configure the cell...
cell.textLabel.text = mRootBeer.name;
cell.detailTextLabel.text = mRootBeer.brewer;
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (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
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[GlobalData sharedData].mViewManager pushView:DETAILVIEW animated:YES];
}
#end
I believe this is why...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
rootList =[[GlobalData sharedData].mRootBeers getRootBeers];
NSLog(#"RootList: %#", rootList);
// Return the number of sections.
NSLog(#"RootList count: %i", rootList.count);
return rootList.count;
}
change it to this.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
You are adding a section for each object in rootList, and then adding all of rootlist in each section. So returning only one section is easiest.
Related
I'm trying to be able to insert an object into my table, but it crashes because of an uncaught exception whenever I hit the add button. It says
Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update
Here's my main view controller which handles all my table stuff...
#import "MasterViewController.h"
#import "DetailViewController.h"
#define kFileName #"steakNames.plist"
#interface MasterViewController () {
NSMutableArray *_objects;
}
#end
#implementation MasterViewController
#synthesize steakName;
- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFileName];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Master", #"Master");
}
return self;
}
- (void)viewDidLoad
{
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
_objects = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)insertNewObject:(id)sender
{
if (!steakName) {
steakName = #"No name";
}
[_objects insertObject:[self steakName] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects.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] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSDate *object = [_objects objectAtIndex:indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[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.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
}
NSDate *object = [_objects objectAtIndex:indexPath.row];
self.detailViewController.detailItem = object;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
- (void)applicationWillResignActive:(NSNotification *)notification {
[_objects writeToFile:[self dataFilePath] atomically:YES];
}
#end
Most likely the cause of the error is that this returns 0:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ...;
}
I would suggest that you first take a complete working example of table view with all its required methods and start from there.
Generally you need to implement these methods:
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
So far there is no issue with any NSMutableArray, anyway you cannot insert an object at an index if the array does not yet have the number of objects, eg insert at index 4 but the array has only 2 objects. You can always add objects to NSMutableArray and increase the number of objects in this array.
After searching all over internet for a long time, but not getting the appropriate answer. I am putting the UITableView in editing mode and selecting multiple rows at a time. It is working great, but I wanted to change the color of checkmark from red to blue same as it is in the iPhone email app.
Any help would be appreciated.
Edited Version:
Here is my code...
in my ViewDidLoad function:
- (void)viewDidLoad
{
...
[deviceTableVIew setAllowsSelectionDuringEditing:YES];
[deviceTableVIew setAllowsMultipleSelectionDuringEditing:YES];
[super viewDidLoad];
}
I have two UIButtons whhich set the editing mode for the tableview as follows:
-(IBAction)control:(id)sender{
btnControl.enabled = false;
btnControl.hidden = true;
btnCancel.enabled = true;
btnCancel.hidden = false;
stateToggleToolbar.hidden = false;
[self.deviceTableVIew setEditing:YES animated:YES];
}
-(IBAction)cancel:(id)sender{
btnCancel.enabled = false;
btnCancel.hidden = true;
btnControl.enabled = true;
btnControl.hidden = false;
stateToggleToolbar.hidden = true;
[self.deviceTableVIew setEditing:NO animated:YES];
}
The UITableView delegate methods are:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//setting up the cells here
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
if ([tableView isEditing] == YES) {
// Do Nothing
}else{
[self.navigationController pushViewController:viewController animated:YES];
}
}
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return 3;
}
One line solution is here)
Just set cell tintColor in your cellForRow:atIndexPath method.
cell.tintColor = UIColor.red
Below is swift code:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
{
//get cell to configure from tableView
let cell = tableView.dequeueReusableCellWithIdentifier("myCellIdentifier", forIndexPath: indexPath) as UITableViewCell
//This line will change checkmark color of your awesome cell
cell.tintColor = UIColor.redColor()
// Configure cell
// ...
//work is done! Let put the cell back to the tableView))
return cell
}
And this is the result of selected and not selected cells::
You cant change checkmark color as its not supported.The thing which you can do is make an image and add following code in your cellForRowAtIndexPath
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
selected=[[NSMutableArray alloc] init];
for(int i=0;i<10;i++){
[selected addObject:#"0"];
}
}
- (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] autorelease];
}
cell.textLabel.text=[NSString stringWithFormat:#"hello %d",indexPath.row];
if([[selected objectAtIndex:indexPath.row] isEqualToString:#"1"]){
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
else{
cell.accessoryType=UITableViewCellAccessoryNone;
}
// Configure the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[selected objectAtIndex:indexPath.row] isEqualToString:#"0"]){
[selected replaceObjectAtIndex:indexPath.row withObject:#"1"];
}
else{
[selected replaceObjectAtIndex:indexPath.row withObject:#"0"];
}
[tbl reloadData];
}
You can change the checkmark image. Create check mark image with check mark image and color.
Then replace image name in the below code. This works fine for iOS 6 and below
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (self.isEditing) {
if (selected){
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
for (UIView *aView in subview.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITableViewCellEditControl"]) {
[aView.layer setContents:(id)[UIImage imageNamed:#"delete_check.png"].CGImage];
}
}
}
}
}
}
}
I want to select multiple rows in UITableview. I can select but my problem is when I scroll the UITableView there is an automatic selection of particular row.
I am using this code :
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {
[selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else {
[selectedCell setAccessoryType:UITableViewCellAccessoryNone];
}
}
Further code is use for the multiple selection in UITableview
#import "RootViewController.h"
#implementation RootViewController
#synthesize arForTable = _arForTable;
#synthesize arForIPs = _arForIPs;
- (void)viewDidLoad {
[super viewDidLoad];
self.arForTable=[NSArray arrayWithObjects:#"Object-One",#"Object-Two",#"Object-Three",#"Object-Four",#"Object-Five", nil];
self.arForIPs=[NSMutableArray array];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.arForTable 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] autorelease];
}
if([self.arForIPs containsObject:indexPath]){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
} else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
cell.textLabel.text=[self.arForTable objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if([self.arForIPs containsObject:indexPath]){
[self.arForIPs removeObject:indexPath];
} else {
[self.arForIPs addObject:indexPath];
}
[tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end
For more details regrading multiple selection Please Refer following link here.
You can have a look on the following article.
http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/3481-uitableview-tutorial-part-2-a.html
Well something is wrong but i dont know what. I cannot delete a row . when my tableview get in editmode red minus signs near all rows appear . touch on them make to appear delete button on row , whem i touch it it become (dark red) and nothing happens.
here is my code (not all) + i have no errors and warnings at compilation and runtime ...
- (void)viewDidLoad {
[super viewDidLoad];
// initialize singleton.
appDelegate = (ExchangedAppDelegate *)[[UIApplication sharedApplication]delegate];
// get banks from settings.plist
NSString *tempPath = [self getPathOfSettingsPlist];
appDelegate.banks = [[NSArray alloc]initWithContentsOfFile:tempPath];
navigationItem.rightBarButtonItem = self.editButtonItem;
backButton = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonSystemItemCancel target:self action:#selector(closeSettingsView)];
navigationItem.leftBarButtonItem = backButton;
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[banksTableView setEditing:editing animated:animated];
if (editing) {
addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addBankFromList)];
navigationItem.leftBarButtonItem = addButton;
} else {
navigationItem.leftBarButtonItem = backButton;
NSString *tempPath = [self getPathOfSettingsPlist];
self.picker.hidden = YES;
[appDelegate.banks writeToFile:tempPath atomically:YES];
}
}
- (void)addBankFromList {
// not interesting
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [appDelegate.banks count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"BanksTableCell";
indexForPath = indexPath;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellEditingStyleNone;
}
cell.textLabel.text = [appDelegate.banks objectAtIndex:indexPath.row];
return cell;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle: forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[appDelegate.banks removeObjectAtIndex:indexPath.row];
[banksTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
[banksTableView reloadData];
}
}
//// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSString *temp = [appDelegate.banks objectAtIndex:fromIndexPath.row];
[appDelegate.banks removeObjectAtIndex:fromIndexPath.row];
[appDelegate.banks insertObject:temp atIndex:toIndexPath.row];
}
Actually you have added an extra colon(":") in the commitEditingStyle: method name. Adding the extra colon has made this method a completely different method. So, your view controller thought that you haven't implemented the commitEditingStyle: method and didn't do anything while you edit your table view.
Just remove the colon(":") after editingStyle in the commitEditingStyle: method. That will fix the problem. That line should look like this,
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
I'm playing around with moving uitableviewcells, and for whatever reason,
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone; //<-- bp set on it
}
isn't getting called (I've set a breakpoint on it) - so the table is showing the delete option, but I don't want that. Here's my implementation:
#implementation MoveItController
#synthesize mList;
- (IBAction)moveButton
{
[self.tableView setEditing:!self.tableView.editing animated:YES];
[self.navigationItem.rightBarButtonItem setTitle:(self.tableView.editing)? #"Done" : #"Move"];
}
- (void)viewDidLoad
{
if (mList == nil)
{
mList = [[NSMutableArray alloc] initWithObjects:#"$1", #"$2", #"$5", #"$10", #"$20", #"$50", #"$100", nil];
}
UIBarButtonItem *mvButton = [[UIBarButtonItem alloc]
initWithTitle:#"Move"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(moveButton)];
self.navigationItem.rightBarButtonItem = mvButton;
[mvButton release];
[super viewDidLoad];
}
// Table datasource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *moveItCellId = #"moveItCellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moveItCellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moveItCellId] autorelease];
cell.showsReorderControl = YES;
}
cell.textLabel.text = [mList objectAtIndex:[indexPath row]];
return cell;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
id object = [[mList objectAtIndex:[fromIndexPath row]] retain];
[mList removeObjectAtIndex:[fromIndexPath row]];
[mList insertObject:object atIndex:[toIndexPath row]];
[object release];
}
- (void) dealloc
{
[mList release];
[super dealloc];
}
#end
No warnings at compile time.
Thanks!
You need to set multiple selection to NO in editing mode
self.tableview.allowsMultipleSelectionDuringEditing = NO;
Try capitalizing the method name properly
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
That's with the S in editingStyleForRowAtIndexPath capitalized. ObjC selectors are case sensitive. The table view does not think it's delegate responds to the method you are trying to provide a return value to.
Another reason might be that you also need to implement
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
Another reason for editingStyleForRowAtIndexPath (and other delegates) not being called is if the control does not have it's delegate outlet connected to the File's Owner.
Yes, this is obvious but it's easily overlooked.