繁体   English   中英

带有文本字段和按钮的Tableview单元格

[英]Tableview cell with textfields and button

我有一个tableviewcell,其中有两个文本字段和一个按钮。 想法是您填写文本字段,但是该按钮将调出另一个具有某种计算器的viewcontroller。

我的问题是将值带回到正确的单元格和文本字段中。

我在“配置”单元格中单击此按钮。

[cell setDidTapButtonBlock:^(id sender) {
    [self countNotes:cashoutLine.cashCurrency cell:cell];

}];

这称为代码摘录;

-(void)countNotes:(Currency *)cashCurrency cell:(PouchEntryViewCell *)cell
{

    NotesCountViewController *notesCountVC = [[NotesCountViewController alloc] init];
    notesCountVC.noteCurrency = cashCurrency;

    notesCountVC.notesDelegate = self;

     notesCountVC.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:notesCountVC animated:YES completion:nil];
}

一切顺利,新的ViewController出现了。 我在那里进行工作,并使用委托将总数传回。 它很高兴地到达第一个视图控制器中,但随后我被卡住了。 如何获得它以填充正确的单元格?

NotesCountViewController

- (id) initWithIndexPath:(NSIndexPath *) indexPath {

    self = [super init];

    if (self) {
        self.indexPath = indexPath;
    }

    return self;
}

在您的.h中声明它,并添加一个indexPath属性。然后只需在您的委托回调中添加self.indexPath即可。

要调用它,只需执行以下操作:

NotesCountViewController *notesCountViewController = [[NotesCountViewController alloc] initWithIndexPath:[self.tableView indexPathForCell:cell];

然后在del回调中检索单元格:

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

假设您要从充当UITableViewDataSource委托的ViewController中呈现计算器,则可以通过在NotesCountViewController中创建NSIndexPath属性来找到正确的单元格来更新文本字段。 在呈现视图控制器之前,请设置属性。 当关闭它时,将NSIndexPath传递回UITableViewDataSource viewController,并使用它找到正确的单元格。

-(void)countNotes:(Currency *)cashCurrency cell:(PouchEntryViewCell *)cell atIndex:(NSIndexPath *)indexPath
{
    NotesCountViewController *notesCountVC = [[NotesCountViewController alloc] init];
    notesCountVC.noteCurrency = cashCurrency;

    notesCountVC.cellIndexPath = indexPath;

    notesCountVC.notesDelegate = self;
    notesCountVC.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:notesCountVC animated:YES completion:nil];
}

然后使用以下命令在Delegate回调中获取单元格

PouchEntryViewCell *cell = (PouchEntryViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
cell.textField.text = @"New Text";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM