选择表格视图单元格时更改按钮的标题

时间:2013-05-13 14:59:23

标签: ios uitableview uibutton

我有一些按钮说明:"点击填写.."。点击它们时会弹出一个表格视图,其中包含选项。如何将这些选项链接到按钮,以便"点击以填写..."被用户选择的数据/行替换?我不知道从哪里开始,提前谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个:

- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
     NSUInteger row = [indexPath row];
     NSString *newText = [youArray objectAtIndex:row]; //yourArray contains your datas (of type NSString in this example)

     //consider your button btn is an inst var
     [btn setTitle:newText forState:UIControlStateNormal];
}

答案 1 :(得分:0)

//在viewcontroller .h文件中创建以下属性,弹出按钮单击

@property (strong, nonatomic) UIButton  *button;

//按下按钮点击弹出视图,如下所示

YourTableViewController *tables = [UITableviewController alloc] init];
tables.button = buttonObjectWhoesTextYouWantToChange;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables];
popover.delegate = self;
popover.popoverContentSize=CGSizeMake(280.0, 327.0);

//现在在tableviewcontroller的didSelectRowAtIndexPath方法中添加这一行

self.button.text = cell.textLabel.text;
相关问题