将Google Spreadsheet Cell数据导入Xcode UITextfield [英] Import Google Spreadsheet Cell data to Xcode UITextfield

查看:127
本文介绍了将Google Spreadsheet Cell数据导入Xcode UITextfield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Google电子表格的特定单元格上获取数据,并将其显示到iOS应用文本字段。例如,此Spreadsheet https:// docs。 google.com/a/ttttt.us/spreadsheet/ccc?key=0AkgWFqjLQz0TdEJSb3pYem9UcHo1Uzd0SU1QWm5xRFE#gid=0



我有一个iOS应用程序,它有2个文本字段。我想在每个文本字段上显示此单元格。每次该应用程序打开时,或者如果电子表格中的数据发生更改,可能需要刷新一段时间。我希望有人能帮助我,谢谢。!

编辑:

我忘了说我有一个SpreadSheetApp委托,可以显示一列文本到UIPickerView,当我点击连接到该插座的文本字段时,它显示文本,我可以选择我想要的。

  NSString * theURL = @https://docs.google.com/spreadsheet/pub?key=0AkgWFqjLQz0TdHdMQzBsc1lhaGFPZEFCYXBLWEt1Q0E&single=true&gid=1&output=txt; 
NSString * theFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:theURL] encoding:NSUTF8StringEncoding error:nil];
NSLog(@%@,theFile);
NSArray * theCells = [theFile componentsSeparatedByString:@\\\
];

这是选取器视图代码:

< (NSInteger)行$ b $ inComponent:(NSInteger)组件
{
switch(selectedTable){pre $ - (void)pickerView:(UIPickerView *)pickerView didSelectRow: ){
case 0:
self.txtLocation.text = [self.ar objectAtIndex:row];
休息;
案例1:
self.txtQuantity.text = [self.ar objectAtIndex:row];
休息;

现在,我如何显示文本而不使用选择器视图来选择它,而是会自动键入在应用程序打开时在文本框中输入。

解决方案

这是一个两步过程。首先,你必须定期下载xls文件来处理数据。根据我的知识,没有办法基本上聆听文件中特定单元格的更改,尤其是因为无法将您认证为该文件的所有者。所以这几乎让您只需定期下载文件并检查更改(如您所期望的那样)。为此,您将使用 Google iOS API 签署并下载该文件。其次,您需要解析xls文件以获取您感兴趣的单元格的值,以及检查更改。有关如何解析xls文件,请参阅



一次你有单元的新价值,你只需将它与旧的(理想情况下存储在核心数据条目中)进行比较,并根据需要更新数据条目和文本字段。


Is it possible to Get the data on a specific cell on Google spreadsheet and show it to iOS app Text fields. For Example, this Spreadsheet https://docs.google.com/a/ttttt.us/spreadsheet/ccc?key=0AkgWFqjLQz0TdEJSb3pYem9UcHo1Uzd0SU1QWm5xRFE#gid=0

I have an iOS app that has 2 Text fields. I want to show this Cells on each textfields I have. Everytime that the App opens, or maybe have some interval to refresh if the data in spreadsheet is changed. I hope someone will help me, thank you.!

EDIT:

i forgot to tell that i have a SpreadSheetApp delegate that can show a column of text to UIPickerView, when i click a text field that connected to that outlet, it shows the text and i can choose what i want.

NSString *theURL = @"https://docs.google.com/spreadsheet/pub?key=0AkgWFqjLQz0TdHdMQzBsc1lhaGFPZEFCYXBLWEt1Q0E&single=true&gid=1&output=txt";
    NSString *theFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:theURL] encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@",theFile);
    NSArray *theCells = [theFile componentsSeparatedByString:@"\n"];

and this is the picker view code:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
      inComponent:(NSInteger)component
{
    switch (selectedTable) {
        case 0:
            self.txtLocation.text = [self.ar objectAtIndex:row];
            break;
        case 1:
            self.txtQuantity.text = [self.ar objectAtIndex:row];
            break;

now, how can i show the text without using picker view to select it, Instead it will automatically type in textfield when the app opens.

解决方案

This is a two step process. Firstly, you have to download the xls file on a regular basis to process the data. Per my knowledge, there's no way to essentially "listen" for changes on a particular cell in a file, especially since there's no way to authenticate you as the owner of that file. So that pretty much leaves you with just downloading the file on a regular basis and checking for changes (as you seem to expect). For that, you'll use the Google iOS API to sign in and download the file. See the example project on the linked website for that.

Secondly, you'll need to parse the xls file to get the value of the cell you're interested in and check for changes. See this answer on how to parse xls files.

Once you have the new value of the cell, you'll just compare it to the old one (ideally stored in a Core Data entry) and update the data entry and text field if needed.

这篇关于将Google Spreadsheet Cell数据导入Xcode UITextfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆