我正在尝试传递我创建的uitableviewcell中的文本标签,但我不确定执行此操作所需的参数。
我有一个NSObject,其方法有一个NSString对象作为参数,这也是我想从我的uitableviewcell标签传递信息的地方......
我有#imported .h文件并在视图tableViews:didSelectRowAtIndexPath方法中设置对象但是我不知道如何将文本从标签传递给我,这是我尝试过但我有兼容性警告..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//initalize object to hold search parameters
VehicleSearchObject *vehicleSearchObject = [[VehicleSearchObject alloc] init];
[self.navigationController popViewControllerAnimated:YES]; //pops current view from the navigatoin stack
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//--- this if block allows only one cell selection at a time and is passing the text in the cells label back to the object
if (oldCheckedData == nil) { // No selection made yet
oldCheckedData = indexPath;
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[vehicleSearchObject GetManufacturers:[[cell textLabel] objectAtIndex:[indexPath row]] // This is where I try to pass the text back but not sure how to do it..
}
else {
UITableViewCell *formerSelectedcell = [tableView cellForRowAtIndexPath:oldCheckedData]; // finding the already selected cell
[formerSelectedcell setAccessoryType:UITableViewCellAccessoryNone];
[cell setAccessoryType:UITableViewCellAccessoryCheckmark]; // 'select' the new cell
oldCheckedData=indexPath;
}
}
答案 0 :(得分:1)
您只需执行以下操作即可引用单元格标签文本:
cell.textLabel.text
即。
[vehicleSearchObject GetManufacturers:cell.textLabel.text];
答案 1 :(得分:1)
你必须这样做。
[vehicleSearchObject GetManufacturers:cell.textLabel.text];
答案 2 :(得分:0)
[[cell textLabel] setText:[vehicleSearchObject GetManufacturers:[[cell textLabel] text]];