Tuesday, 30 December 2014

Getting row of UITableView cell on button press


CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];


NSLog(@"index: %ld",(long)indexPath.section);

NSLog(@"index: %ld",(long)indexPath.row);

Add a multiple buttons to a view programatically

for( int i = 0; i < 5; i++ ) {
  UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  [aButton setTag:i];
  [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
  [aView addSubview:aButton];
}

// then ...

- (void)buttonClicked:(UIButton*)button
{
  NSLog(@"Button %ld clicked.", (long int)[button tag]);
}

Friday, 19 December 2014

Insert new cells in a UITableView (OR) Middle of the UITableView



[self.dataSourceArray insertObject:object atIndex:indexPath.row];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];


(OR)


    NSInteger row = 1;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];

    [self.dataSourceArray insertObject:object atIndex:indexPath.row];
    [self.ItineraryTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];