UITableViewCell 上添加 UIButton 点击有时有反应 有时没有
展开全部
[objc]view plaincopy
- (UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*identifier =@"Cell";
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:reuseIdentifier];
if(cell ==nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];
cell.selectionStyle= UITableViewCellSelectionStyleNone;
}
User*user = _users[indexPath.row];
cell.user= user;
//拍照button
UIButton *photographButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
photographButton.frame= CGRectMake(221,10,100,44);
[photographButtonsetImage:[UIImageimageNamed:@"camera.png"]forState:UIControlStateNormal];
[photographButtonaddTarget:selfaction:@selector(photographButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
photographButton.tag= indexPath.row;
[cell.contentViewaddSubview:photographButton];
returncell;
}
然后在点击事件中取数据,加信息
[objc]view plaincopy
- (void)photographButtonClicked:(UIButton*)sender{
User*user = _users[sender.tag];
PhotoPickerController*photoPicker = [[PhotoPickerControlleralloc]init];
photoPicker.user= user;
[self.navigationControllerpushViewController:photoPickeranimated:YES];
}
- (UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*identifier =@"Cell";
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:reuseIdentifier];
if(cell ==nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];
cell.selectionStyle= UITableViewCellSelectionStyleNone;
}
User*user = _users[indexPath.row];
cell.user= user;
//拍照button
UIButton *photographButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
photographButton.frame= CGRectMake(221,10,100,44);
[photographButtonsetImage:[UIImageimageNamed:@"camera.png"]forState:UIControlStateNormal];
[photographButtonaddTarget:selfaction:@selector(photographButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
photographButton.tag= indexPath.row;
[cell.contentViewaddSubview:photographButton];
returncell;
}
然后在点击事件中取数据,加信息
[objc]view plaincopy
- (void)photographButtonClicked:(UIButton*)sender{
User*user = _users[sender.tag];
PhotoPickerController*photoPicker = [[PhotoPickerControlleralloc]init];
photoPicker.user= user;
[self.navigationControllerpushViewController:photoPickeranimated:YES];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询