开发者

How to add Custom EditingAccessoryView for UITableView?

开发者 https://www.devze.com 2023-01-22 07:38 出处:网络
i want to add 开发者_开发问答custom EditingAccessoryView in cell, when user swipe in place of delete button i want to show my custom view.There doesn\'t seem to be a function for that. All you can do

i want to add 开发者_开发问答custom EditingAccessoryView in cell, when user swipe in place of delete button i want to show my custom view.


There doesn't seem to be a function for that. All you can do is give a custom text for the Delete confirmation button, by using the function below.

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath


Design view from xib like bellow example

How to add Custom EditingAccessoryView for UITableView?

now make IBOutlet of uiview in .h file

IBOutlet UIView *accessoryView;

connect that IBOutlet to your design view.

now in .m file set that view as editingAccessoryView of table cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.editingAccessoryView = accessoryView;

       }

}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {

   return NO;

}

now when you swipe your custom view will show in place of delete button

0

精彩评论

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