开发者

How to set editing is yes for a particular section in iPhone

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.


Implement

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜