19 July, 2012

Iphone Questions



Programmatically show the red delete button on a UITableViewCell?


Answer :-

In the doubleFingerSwipe gesture's selector method set one variable and assign as no of row swiped and reload the table . 
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == yourVariable) return UITableViewCellEditingStyleDelete;
    else return UITableViewCellEditingStyleNone;
}


Dynamically adding images in UITableView using for loop -objective c


Answer :-

UIImageView *img[20];//ur array of images
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
for (int i=0; i<20; i++) {

        //set frame  every time as ur requirement

        img[i].image = [UIImage imageNamed:[NSString stringWithFormat:@"testImg%d",i+1]];
        [cell.contentView addSubview:img[i]];
    }
}