0

嗨,我正在实施一个表格,我收到请求我有学生列表,我想添加为我的室友我有两个按钮接受和拒绝当我点击接受按钮时问题就在这里从数组中删除,并且我想在接受请求的情况下将删除的行值转移到 nextview 控制器的表中。并且如果单击拒绝按钮只想删除行而不是将单元格的值移动到下一个视图控制器中我正在使用情节提要实现这个项目任何人都可以知道请分享我这是代码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;

}
4

2 回答 2

1

简而言之,您可以通过单击UIbutton如下方式删除选定的行:-

-(IBAction)Acceptrequest:(id)sender
{
UIButton *btn =(UIButton*)sender;

[myarray removeObjectsAtIndexes:btn.tag];
[tableView deleteRowsAtIndexPaths:myarray withRowAnimation:UITableViewRowAnimationAutomatic];

[tableVIew reloadData];
}
于 2013-01-21T10:16:41.477 回答
0

你需要实现这个方法:

[tableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
于 2013-01-21T10:12:11.850 回答