ios - 如何将 [didSelectRowAtIndexPath] 选中的单元格变成字符串供以后使用

标签 ios iphone nsstring didselectrowatindexpath nsindexpath

我正在寻找一种方法来添加通过 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/

相关文章:

ios - 滚动时 UITableViewCell 内容发生变化,因为在其中一个单元格中运行计时器

iphone - UIWebView - 加载页面

ios - 如何在 IOS 7 的 UISearchBar 中更改位置或隐藏放大镜图标?

objective-c - 覆盖粘贴: to format text

objective-c - 在 Cocoa 中的不同类中设置变量

iOS - Hook 到 .EditingDidEndOnExit

ios - Restkit-如何在表格 View 中显示 json 数据

iphone - 如何将 NSArray 转换为 NSString

ios - 自动滚动到 ScrollView 中的 subview

iphone - PhoneGap + iOS 异常 : [UIWebOverflowScrollView _viewDelegate] message sent to deallocated instance 0x21e330