gpt4 book ai didi

ios - 如何根据警报 View 选择从 didselectrowatindexpath 更改单元格

转载 作者:行者123 更新时间:2023-11-28 22:08:03 25 4
gpt4 key购买 nike

如果用户在弹出的警报 View 上单击肯定,我会在 didselectrowatindexpath 的 TableView 中执行一个操作。我想根据用户是否在警报 View 上单击 Yet 来更改单元格属性中的文本。

我的代码如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
InviteTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Invite *invite = [self.inviteContactsArray objectAtIndex:indexPath.row];
_selectedRow = indexPath;

NSString *message = [NSString stringWithFormat:@"Are you sure you want to send an email invite ?"];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Confirm Invite" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

[alert show];
}

警报然后发出邀请,但我希望它也将单元格上的标签更改为“已邀请”。我试过了,但没用。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
NSLog(@"fire invite");
[self invite];
InviteTableViewCell *cell = [self.tableView cellForRowAtIndexPath:_selectedRow];
cell.inviteLabel.text = @"invited";
[self.tableView reloadRowsAtIndexPaths:@[_selectedRow] withRowAnimation:UITableViewRowAnimationAutomatic];

}

}

用户在警报 View 上选择尚未邀请后,如何更改单元格?

最佳答案

你正在改变一个被丢弃的细胞!

cell.inviteLabel.text = @"invited"; // <-- This cell will no longer exist after next call.
[self.tableView reloadRowsAtIndexPaths:@[_selectedRow] withRowAnimation:UITableViewRowAnimationAutomatic];

您需要更新您的模型,然后当重新加载单元格时,模型将使用单元格的新值。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
NSLog(@"fire invite");
[self invite];

// However you need to record this update to the data model
MyObject *object = self.objects[indexPath];
object.invited = YES;

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


// Now you use the data model to provide the correct value for the reloaded cell.
MyObject *object = self.objects[indexPath];
if (object.invited)
cell.inviteLabel.text = @"invited";


}

关于ios - 如何根据警报 View 选择从 didselectrowatindexpath 更改单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23505328/

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