plus minus table View cell
Posted
by
user1748387
on Stack Overflow
See other posts from Stack Overflow
or by user1748387
Published on 2012-11-26T05:00:10Z
Indexed on
2012/11/26
5:03 UTC
Read the original article
Hit count: 159
I have the following code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIImage * i1 = [UIImage imageNamed: @"inc_01.png"];
UIImage * i2 = [UIImage imageNamed: @"inc_02.png"];
UIImage * i3 = [UIImage imageNamed: @"inc_04.png"];
UIImage * i5 = [UIImage imageNamed: @"inc_05.png"];
UIImage * i6 = [UIImage imageNamed: @"inc_06.png"];
UIImage * i7 = [UIImage imageNamed: @"inchd.png"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(indexPath.row == 0)
{
UIImageView * header= [[UIImageView alloc] initWithImage: i1];
cell.backgroundView = header;
// Configure the cell…
}
else if (indexPath.row == 2)
{
UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 11)];
backgroundCellImage.image=[UIImage imageNamed:@"inc_06.png"];
[cell.contentView addSubview:backgroundCellImage];
}
else
{
// Configure the cell…
UIImageView *imageView = [[UIImageView alloc] initWithImage: i3];
cell.textLabel.text = @"text";
UIImageView *backgroundCellImage=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 57, 46)];
backgroundCellImage.image=[UIImage imageNamed:@"inc_02.png"];
UIImageView *backgroundCellImage2=[[UIImageView alloc] initWithFrame:CGRectMake(223, 0, 57, 46)];
backgroundCellImage2.image=[UIImage imageNamed:@"inc_04.png"];
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(57, 0, 166, 46)];
label.text = @"wow";
[cell.contentView addSubview:backgroundCellImage];
[cell.contentView addSubview:backgroundCellImage2];
[cell.contentView addSubview:label];
}
return cell;
}
that basically creates a table view and puts an image to the left and right of each cell. I want it so that people can click on the left or right image in each cell, and something different happens based on the cell number.
So if they click on the left image for cell in row 1, a function gets call with the row number they clicked on, and an indicator telling me they clicked on the left image and not the right image.
How can I do that using objective-c?
© Stack Overflow or respective owner