Мое требование состоит в том, чтобы управлять строками таблицы для избранных, выберите все и удаление. /> viewController.h
@interface ViewController : UIViewController
{
NSMutableArray *tableData;
NSMutableSet *selectedRows;
UIToolbar *actionToolbar;
UIImageView *imgView;
BOOL selected;
UIBarButtonItem *actionButton,*selectAllButton,*deleteButton;
}
@property(nonatomic,retain)NSMutableSet *selectedRows;
@property(nonatomic,retain)IBOutlet UITableView *tableView;
- (BOOL)selected;
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer;
- (NSIndexPath *)indexPathForCellController:(id)cellController;
< /code>
viewcontroller.m
#import "ViewController.h"
#import "MultiSelectTableViewCell.h"
@interface ViewController ()
@end
const NSInteger SELECTION_INDICATOR_TAG = 54321;
const NSInteger TEXT_LABEL_TAG = 54322;
@implementation ViewController
@synthesize tableView,selectedRows;
- (void)viewDidLoad
{
[super viewDidLoad];
tableData=[[NSMutableArray alloc]init];
[tableData addObject:@"Row1"];
[tableData addObject:@"Row2"];
[tableData addObject:@"Row3"];
[tableData addObject:@"Row4"];
[tableData addObject:@"Row5"];
[tableData addObject:@"Row6"];
[tableData addObject:@"Row7"];
[tableData addObject:@"Row8"];
[tableData addObject:@"Row9"];
[tableData addObject:@"Row10"];
selectedRows=[[NSMutableSet alloc]init];
actionToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)];
actionButton =
[[UIBarButtonItem alloc]
initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(noAction:)];
NSMutableArray *buttons = [[NSMutableArray alloc ]initWithCapacity:2];
selectAllButton=[[UIBarButtonItem alloc]initWithTitle:@"Select All" style:UIBarButtonItemStyleBordered target:self action:@selector(selectAllrows:)];
deleteButton=[[UIBarButtonItem alloc]initWithTitle:@"Delete" style:UIBarButtonItemStyleBordered target:self action:@selector(deleterows:)];
[self.tableView setAllowsSelectionDuringEditing:YES];
self.tableView.allowsMultipleSelection = YES;
selected=NO;
[buttons addObject:actionButton];
[buttons addObject:selectAllButton];
[buttons addObject:deleteButton];
[actionToolbar setItems:buttons];
[self.view addSubview:actionToolbar];
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 2.0; //seconds
lpgr.delegate = self;
[self.tableView addGestureRecognizer:lpgr];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@"long press on table view but not on a row");
else
NSLog(@"long press on table view at row %d", indexPath.row);}
- (void)noAction:(id)sender
{
}
- (void)deleterows:(id)sender
{
// [self.tableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"select rows are::%@ %d",selectedRows,[selectedRows count]);
NSArray *array=[selectedRows allObjects];
NSLog(@"indexes are::%@",array);
for (int i=0; i
multiselecttableviewcell.h
#import
@interface MultiSelectTableViewCell : UITableViewCell
{
}
@end
extern const NSInteger EDITING_HORIZONTAL_OFFSET;
< /code>
multiselecttableviewcell.m
#import "MultiSelectTableViewCell.h"
const NSInteger EDITING_HORIZONTAL_OFFSET = 30;
@implementation MultiSelectTableViewCell
//
// setEditing:animated:
//
// Refreshed the layout when editing is enabled/disabled.
//
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self setNeedsLayout];
}
//
// layoutSubviews
//
// When editing, displace everything rightwards to allow space for the
// selection indicator.
//
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 30;
self.contentView.frame = contentFrame;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 30;
self.contentView.frame = contentFrame;
}
[UIView commitAnimations];
}
@end
Подробнее здесь: https://stackoverflow.com/questions/150 ... iew-in-ios
Изображение таблицы не изменяется при выборе строки таблицы в iOS ⇐ IOS
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение