[英]how to delete row in uitableview when click on button
您好,我正在实施一个表格,我在其中收到请求,我要添加到我的房间列表中,作为我的室友,我有两个按钮接受和拒绝的问题在这里,当我单击接受按钮时,我希望该行从数组中删除,并且在接受请求的情况下,我还想将已删除的行值移入nextview控制器的表中。 并且在拒绝按钮的情况下,仅希望删除该行而不要将单元格的值移动到下一个视图控制器中,我正在使用情节提要实现该项目,有人可以对此有想法吗?这是cellForRowAtIndexPath:
的代码cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DefaultCell"];
if(cell == nil) {
cell =[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"DefaultCell"];
}
acceptreq = [UIButton buttonWithType:UIButtonTypeRoundedRect];
acceptreq.frame =CGRectMake(170, 10, 60, 30);
rejectreq = [UIButton buttonWithType:UIButtonTypeRoundedRect];
rejectreq.frame =CGRectMake(240, 10, 60, 30);
[acceptreq setTitle:@"Accept" forState:UIControlStateNormal];
[rejectreq setTitle:@"Reject" forState:UIControlStateNormal];
[acceptreq addTarget:self action:@selector(Acceptrequest:) forControlEvents:UIControlEventTouchUpInside];
[rejectreq addTarget:self action:@selector(Rejectrequest:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:acceptreq];
[cell addSubview:rejectreq];
[acceptreq setTag:indexPath.row];
cell.textLabel.text = [myarray objectAtIndex:indexPath.row];
return cell;
}
简而言之,您可以点击下面的UIbutton
删除选定的行:-
-(IBAction)Acceptrequest:(id)sender
{
UIButton *btn =(UIButton*)sender;
[myarray removeObjectsAtIndexes:btn.tag];
[tableView deleteRowsAtIndexPaths:myarray withRowAnimation:UITableViewRowAnimationAutomatic];
[tableVIew reloadData];
}
您需要实现此方法:
[tableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.