iphone app - 服务器上的plist(自动刷新)

时间:2011-09-29 11:59:48

标签: xcode plist

我创建了一个带有第二个视图的tableView,其功能是从plist加载数据。它可以工作,但我想将plist放在服务器上,这样当我更改plist上的数据时,app会自动刷新。

代码:

// Get a plist and copy in its contents into an array
- (id)initWithLibraryName:(NSString *)libraryName {
    if ((self = [super init])) {
        libraryPlist = libraryName;
        libraryContent = [[NSArray alloc] initWithContentsOfFile:
                            [[NSBundle mainBundle] pathForResource:libraryPlist
                                                            ofType:@"plist"]];
    }
    return self;
}

// [Safely] returns a "DVD" from the plist. Each item in the data source is a
// dictionary containing data about the chosen DVD. 
- (NSDictionary *)libraryItemAtIndex:(int)index {
    return (libraryContent != nil &&
            [libraryContent count] > 0 &&
            index < [libraryContent count])
                ? [libraryContent objectAtIndex:index] : nil;
}

1 个答案:

答案 0 :(得分:0)

NSURL *url = [NSURL URLWithString:@"http://mydomain.com/file.plist"];
NSDictionary *DICTIONARY = [[NSDictionary alloc] initWithContentsOfURL:url];

其中DICTIONARY将是您表格的数据源