gpt4 book ai didi

ios - 用文本填充单元格中的标签

转载 作者:行者123 更新时间:2023-11-29 12:16:39 24 4
gpt4 key购买 nike

我有一个 tableview 单元格。其中有一个按钮和一个标签。当用户单击按钮时,我想弹出一个消息框,用户可以在其中键入一些文本并提交。在那种情况下(当用户键入文本并提交时)用户键入的文本应该显示在该单元格的 UILabel(在那个特定的 cell 中)。我该怎么做?

cell.cellButton.tag = indexPath.row;
[cell.cellButton addTarget:self action:@selector(cellButtonClicked:) forControlEvents:UIControlEventTouchUpInside];



-(void)cellButtonClicked: (id)sender {

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Enter your text" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok"];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];

}

注意:这是每个单元格的样子 enter image description here

问题:

1.) 如何用文本填充单元格中的标签? (请考虑我已经有了文本)

最佳答案

在按钮操作中将警报 View 的标签设置为

-(void)cellButtonClicked: (id)sender {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Enter your text" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = sender.tag;
[alert show];
}

之后将下面的代码写在 alert view delegate 中

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
NSString *name = [alertView textFieldAtIndex:0].text;
// Insert whatever needs to be done with "name"
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:alertView.tag inSection:0];

UITableViewCell *cell = [_myTableview cellForRowAtIndexPath:indexPath];
for (UIView *view in cell.contentView.subviews) {
if([view isKindOfClass:[UILabel class]]){
UILabel *label = (UILabel*) view;
label.text = name;
}
}
}
}

希望对你有所帮助。

关于ios - 用文本填充单元格中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31823497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com