[英]How to get Tableview selected cell UILabels Value using Objective C?
[英]In Tableview, How to get the textview value of selected row in Objective C
如何获取所选行的textview值,我已经在google中对此进行了搜索,但没有适当的解决方案。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
arr = [[NSArray alloc]initWithObjects:@"Apple",@"ms-dynamicsxrm://?etn=thk_store&pagetype=entityrecord&id=7b74df21-e5a0-e711-810a-5065f38a9b71",@"Micromax",@"Nokia", nil];
}
#pragma mark - Table View Data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return arr.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cell_id";
SecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
cell.label1.text = @"label";
NSString *txtDetailStr = [arr objectAtIndex:indexPath.row];
if ([txtDetailStr containsString:@"ms-dynamicsxrm://"]) {
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:txtDetailStr attributes:@{ NSLinkAttributeName: [NSURL URLWithString:txtDetailStr] }];
cell.textview1.attributedText = attributedString;
}
else {
cell.textview1.text = txtDetailStr;
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
如何获取所选行的textview值,我已经在google中对此进行了搜索,但没有适当的解决方案。
您可以像这样在didSelectRowAtIndexPath
内获取选定行的textview值。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SecondTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSLog(cell.textview1.text);
// If you want to get selected row data from your array then you can access it like this.
NSString *txtDetailStr = [arr objectAtIndex:indexPath.row];
NSLog(txtDetailStr);
}
在这里,我尝试使用自定义UITableViewCell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.tabledata objectAtIndex:indexPath.row];
return cell;
// indexPath.row
指示选择了哪一行并将其设置为标签文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.