我有一个UITableView,我试图在编辑模式处于活动状态时删除一行但是没有触发commitEditingStyle。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.text=[NSString stringWithFormat:@"Row Number %d",indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"trying to delete a row..");
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 6;
}
-(void)Edit:(id)sender //Active editing mode
{
[self.table setEditing:YES animated:YES];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)];
}
我只想删除一行?
这是我展示我的popover的方式:
UIPopoverController *popover;
-(IBAction)open:(id)sender
{
CGRect r=((UIButton*)sender).frame;
CGRect tRect=[((UIButton*)sender) convertRect:((UIButton*)sender).frame toView:self.view];
tRect.origin.x=r.origin.x;
Popover *firstViewCtrl = [[Popover alloc] init];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:firstViewCtrl];
navbar.preferredContentSize = CGSizeMake(300, 300);
popover = [[UIPopoverController alloc] initWithContentViewController:navbar];
popover.delegate = self;
popover.popoverContentSize = CGSizeMake(300, 300);
CGRect popRect = CGRectMake(0,
0,
200,
200);
[popover presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
// [popover presentPopoverFromRect:tRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
我使用Xcode界面创建了UITableView。
-(void)Done:(id)sender
{
[self.table setEditing:NO animated:NO];
//[self.table endEditing:true];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(Edit:)];
}
答案 0 :(得分:8)
触摸删除按钮时会触发,而不是减号...并且由于您的tableview宽度,桌面视图上的删除按钮无法正常显示...
答案 1 :(得分:0)
编辑:看了你的代码后,我认为charty是正确的。
请务必检查编辑样式,并对数据源进行必要的调整。类似的东西:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"deleting");
[_resultsArray removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
}