0

hi i am implementing a table in which i am getting request i have list of students to which i want to add as my room mate i have two button accept and reject the problem is here when i click on accept button i want that row will be deleted from the array and also i want to shift the deleted row value into the table of nextview controller in case of accept request . and in case of reject button cliked only want to delete the row not to move the value of cell into next view controller i am implementing this project by using storyboard can anybody have idea about that plase share me this is the code for 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;

}
3
  • 2
    Please accept answers in your previous questions and improve accpet rate. It will encourage people to help you. =) Commented Jan 21, 2013 at 10:07
  • Delete element from data source and call reload Commented Jan 21, 2013 at 10:20
  • English 100 - End each sentence with a period. Commented Jan 21, 2013 at 10:38

2 Answers 2

1

In short you can delete selected Row with clicking UIbutton like bellow:-

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

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

[tableVIew reloadData];
}
Sign up to request clarification or add additional context in comments.

4 Comments

getting this error /Users/mobitsolutions/Desktop/adnan/BedSpace/RequestViewController.m:64:6: No visible @interface for 'NSArray' declares the selector 'removeObjectsAtIndexes:' on this line [myarray removeObjectsAtIndexes:btn.tag];
myarray = [NSMutableArray array]
another error when click on button i just now declare array as nsmutablearray but when click on button getting this error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString row]: unrecognized selector sent to instance 0x1a120'
I suggest you to go to iOS documentation and read more about use of arrays. The flow is simple: you add to array A the index paths you want to delete, then in tableview you remove those rows. In array B (datasource) you remove the index.
0

You need to implement this method:

[tableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];

1 Comment

It has to be NSMutableArray instead of NSArray

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.