我正在寻找一种方法来添加通过 didDismissWithButtonIndex:
方法在表中选择的 didSelectRowAtIndexPath:
“单元格名称”:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
Database *currentStore = [DBList objectAtIndex:indexPath.row];
NSString *requestStr = @"http://";
requestStr = [requestStr stringByAppendingString:hostTextField.text];
requestStr = [requestStr stringByAppendingString:@":8080/compfile2.php?password="];
requestStr = [requestStr stringByAppendingString:passwordTextField.text];
requestStr = [requestStr stringByAppendingString:@"&db=latinbites"];
requestStr = [requestStr stringByAppendingString:currentStore];
}
显然,
Database *currentStore = [DBList objectAtIndex:indexPath.row];
不正确。有什么方法可以在选定的单元格行上放置一个字符串?
最佳答案
我相信我了解您想要实现的目标。尝试以下代码:-
没有。 1 - 使用 NSString 声明一个属性
@interface TableViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSString * selectedCellName;
@end
没有。 2 - 在 didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
self.selectedCellName = cell.textLabel.text;
}
没有。 3 - 在 didDismissWithButtonIndex 中,附加单元格名称。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
NSString *requestStr = @"http://";
requestStr = [requestStr stringByAppendingString:hostTextField.text];
requestStr = [requestStr stringByAppendingString:@":8080/compfile2.php?password="];
requestStr = [requestStr stringByAppendingString:passwordTextField.text];
requestStr = [requestStr stringByAppendingString:@"&db=latinbites"];
requestStr = [requestStr stringByAppendingString:self.selectedCellName];
}
}
关于ios - 如何将 [didSelectRowAtIndexPath] 选中的单元格变成字符串供以后使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23749577/