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

Ios 更改按钮';选择表格视图单元格时的标题,ios,uitableview,uibutton,Ios,Uitableview,Uibutton,我有一些按钮,上面写着:“点击填写…”。当点击它们时,会弹出一个带有选项的表格视图。如何将这些选项链接到按钮,以使“点击填充…”替换为用户选择的数据/行?我不知道从哪里开始,提前谢谢。试试这个: - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; NSString *ne

我有一些按钮,上面写着:“点击填写…”。当点击它们时,会弹出一个带有选项的表格视图。如何将这些选项链接到按钮,以使“点击填充…”替换为用户选择的数据/行?我不知道从哪里开始,提前谢谢。

试试这个:

- (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];
}

//在单击按钮时弹出的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的DidSelectRowatingIndexPath方法中

self.button.text = cell.textLabel.text;

你好,谢谢你的回复。我按照你的建议做了,但我的按钮似乎没有更新字段。。请你再具体一点好吗?提前感谢。我的数组:NSArray*array=[[NSArray alloc]initWithObjects:@“1”,“2”,“3”,“4”,nil];self.tableViewArray=数组;tableview代码:-(NSInteger)tableview:(UITableView*)tableview行数section:(NSInteger)section{return[tableViewArray count];}-(UITableViewCell*)tableview:(UITableView*)tableview cellForRowAtIndexPath:(NSIndexPath*)indexPath{UITableViewCell*cell=[tableview dequeueReusableCellWithIdentifier:@“SimpleTableIdentifier”];如果(cell==nil){cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@“SimpleTableIdentifier”];}cell.textLabel.text=[tableViewArray objectAtIndex:indexPath.row];返回cell;}在我的代码中,按tableViewArray更改youArray,和btn,对应于要更新的按钮的ivar名称。[u行业设置标题:@“myTitle”用于状态:UIControlStateNormal];将按钮的标题更改为myTitle。但是,当我尝试使用您的代码通过在tableview中选择一行来动态更改标题时,它不会更新。。