iphone - 如何将 NSString 从 uitableviewcell 传递到 NSObject

标签 iphone ios nsobject

我正在尝试传递我创建的 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/

相关文章:

ios - 从横向启动应用程序时在 IOS 中锁定纵向方向

iphone - 在包含错误的 UITextfield 周围制作一个红色边框

ios - 如何在 Swift 中临时存储图像和字符串?

objective-c - performSelectorOnMainThread中的WaitUntilDOne有什么意义?

Objective-C 覆盖 [NSObject initialize] 是否安全?

iphone - 无法连接到生产 Apple 推送通知服务器

ios - 添加 http ://prefix to UITextField in swift

ios - 如何在使用 PhoneGap 构建的 iPhone 应用程序中使用 Google Web 字体?

ios - 为什么UIProgressView设置进度不会停止?

ios - 如何处理来自 facebook api 的字符串响应?