views:

42

answers:

2

I have declared UITableView in .h file. I have 5 section in the table view, now I need to set the tableview.editing= yes only for section 4.

How can I display the + button beside section 4 and have all other sections in editing = NO?

myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,320,415) style:UITableViewStyleGrouped];
        myTableView.delegate = self;
        myTableView.dataSource=self;
        [myTableView setSectionFooterHeight:0];
        [myTableView setSectionHeaderHeight:15];
        [myTableView setSeparatorColor:[UIColor lightGrayColor]];
        myTableView.backgroundColor = [UIColor colorWithRed:0.85546875 green:0.8828125 blue:0.92578125 alpha:1];
        [myView addSubview: myTableView];


I tried like this it is not working.
- (NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section
{
    if(section==0)
    {
        myTableView.editing = NO;
        myTableView.allowsSelectionDuringEditing = NO;
        return 3;
    }
    else if(section ==1)
    {
        myTableView.editing = NO;
        myTableView.allowsSelectionDuringEditing = NO;
        return 2;
    }
    else if(section==4)
    {
        myTableView.editing = YES;
        myTableView.allowsSelectionDuringEditing = YES;
        if(isEdit == YES)
        {
            if([editObject.contactList count]>0)
            {
                return [editObject.contactList count]+1;
            }
            else
            {
                return 1;
            }
        }   
        else if(isEdit == NO)
        {
            if([addContactList count]>0)
            {
                return [addContactList count]+1;
            }
            else
            {
                return 1;
            }
        }

    }
    else if(section==2)
    {
        myTableView.editing = NO;
        myTableView.allowsSelectionDuringEditing = NO;
        return 1;
    }
    else if(section==3)
    {
        myTableView.editing = NO;
        myTableView.allowsSelectionDuringEditing = NO;
        return 1;
    }
    return 0;
}

I am getting the + button in the 4th section, but all other sections are moved to the right side.

A: 

Implement - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath and return UITableViewCellEditingStyleNone for the rows in the sections you don't want to be editable.

nevan
+ icon is not need for others Section, need only for particular section and its rows.
Madan Mohan
A: 

Implement

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
jrtc27
Thank You so much
Madan Mohan
This is kind of obvious but also make sure you have set the allowsSelectionDuringEditing property to true. You can do this in code or in the xib designer.More details here: http://developer.apple.com/iphone/library/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#jumpTo_4
Helephant