Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a sub row in table view cell
    text
    copied!<p>I am working on a project in which I am making a to-do-application and I am making it on table view where I give the functionality an add button on each cell and on click of that button I want to add a child cell in hierarchy to the clicked cell and same for all cells. Can you please tell me how to do this? I will be very thankful.</p> <p>Thank you in advance. Here is a code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; button.tag = indexPath.row; button.frame = CGRectMake(280.0, 10, 25, 30.0); // x,y,width,height [button addTarget:self action:@selector(buttonclicked:) forControlEvents:UIControlEventTouchUpInside]; [cell addSubview:button]; UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:nil]; longPress.delegate = self; [cell addGestureRecognizer:longPress]; int count = 0; if(self.editing &amp;&amp; indexPath.row != 0) count = 1; NSLog([NSString stringWithFormat:@"%i,%i",indexPath.row,(indexPath.row-count)]); // Set up the cell... if(indexPath.row == ([_choices count]) &amp;&amp; self.editing) { cell.textLabel.text = @"ADD"; return cell; } NSString *choice = [self.choices objectAtIndex:indexPath.row]; cell.textLabel.text = choice; return cell; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload