我正在尝试传递我创建的 uitableviewcell 中的文本标签,但我不确定执行此操作所需的参数。
我有一个 NSObject,其方法以 NSString 对象作为参数,这也是我想从 uitableviewcell 标签传递信息的地方...
我已经#imported .h 文件并在 View 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;
}
}
最佳答案
你必须这样做。
[vehicleSearchObject GetManufacturers:cell.textLabel.text];
关于iphone - 如何将 NSString 从 uitableviewcell 传递到 NSObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7383214/