2013年4月2日 星期二

在tableCell中加入button的 方式

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //在cell.accessoryView加入button UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(tipAction:) forControlEvents:UIControlEventTouchDown]; button.tag=indexPath.row+1; [button setTitle:@"Show View" forState:UIControlStateNormal]; button.frame = CGRectMake(20.0, 20.0, 60.0, 40.0); cell.accessoryView = button; //在cell.contentView加入button UIButton *infoButton = [UIButton buttonWithType:102]; [infoButton setFrame:CGRectMake(10,10,infoButton.frame.size.width, infoButton.frame.size.height)]; [infoButton addTarget:self action:@selector(infoButtonTapped) forControlEvents:UIControlEventTouchUpInside]; [cell.contentView addSubview:infoButton]; //在cell.imageView加入button [cell.imageView setImage:[UIImage imageNamed:@"info-button.png"]]; [cell.imageView setUserInteractionEnabled:YES]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(infoImageTapped:)]; [tap setNumberOfTapsRequired:1]; [cell.imageView setGestureRecognizers:[NSArray arrayWithObject:tap]]; [tap release]; }

沒有留言:

張貼留言