如何获取 UITableView 单元格的数据?
How do I get a UITableView' cell's data?
我需要获取所选行的部分数据 (cell.textLabel.text)。问题是这是单元格中的内容(根据调试器),我不知道如何访问它。这是 -didSelectRowAtIndexPath
中的代码行
NSString *cellText = selectedCell.textLabel.text;
这就是 selectedCell.textLabel.text 中的内容:
我这辈子都想不通如何获得 3 个部分中的第一个。
任何 ideas/comments/answers 将不胜感激!
你试过这样的东西吗?
NSString *cellText = selectedCell.textLabel.text;
NSArray *components = [cellText componentsSeparatedByString:@" "];
if (components.count > 0) {
NSString *firstPart = components[0];
NSLog(@"%@", firstPart);
}
我成功了;这是代码:
- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
if(isFiltered) {
Books *su = filteredTableData[indexPath.row];
passedSKU = su.sku;
}
else {
// get the key from the cell that was selected from the list
Books *selectedBook = [booksArray objectAtIndex:indexPath.row];
passedSKU = selectedBook.sku;
}
// programmatically set the tabBar index
[self.tabBarController setSelectedIndex: 1];
}
我需要获取所选行的部分数据 (cell.textLabel.text)。问题是这是单元格中的内容(根据调试器),我不知道如何访问它。这是 -didSelectRowAtIndexPath
中的代码行NSString *cellText = selectedCell.textLabel.text;
这就是 selectedCell.textLabel.text 中的内容:
我这辈子都想不通如何获得 3 个部分中的第一个。
任何 ideas/comments/answers 将不胜感激!
你试过这样的东西吗?
NSString *cellText = selectedCell.textLabel.text;
NSArray *components = [cellText componentsSeparatedByString:@" "];
if (components.count > 0) {
NSString *firstPart = components[0];
NSLog(@"%@", firstPart);
}
我成功了;这是代码:
- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
if(isFiltered) {
Books *su = filteredTableData[indexPath.row];
passedSKU = su.sku;
}
else {
// get the key from the cell that was selected from the list
Books *selectedBook = [booksArray objectAtIndex:indexPath.row];
passedSKU = selectedBook.sku;
}
// programmatically set the tabBar index
[self.tabBarController setSelectedIndex: 1];
}