【发布时间】:2012-10-02 02:22:13
【问题描述】:
首先,我对 Objective-c 和 ios 开发非常陌生。
我有一个从 Internet 下载的 .plist,然后用于填充 UITableView。我可以在 AppDelegate 中的 ApplicationDidLaunch 方法中让它工作,如下所示。
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *finalPath = [path stringByAppendingPathComponent:@"Data.plist"];
NSURL *theFileURL = [NSURL URLWithString:@"http://dl.dropbox.com/u/8068058/Data.plist"];
NSDictionary *replace = [[NSDictionary alloc] initWithContentsOfURL:theFileURL];
if (replace != nil){
[replace writeToFile:finalPath atomically:YES];
}
然后我将它设置为DataPath
NSString *Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];
这一切都很好,然后我填充 TableView 并显示它。如果我向显示表格的 NavgationController 添加一个“刷新”按钮。当我按下它并运行相同的下载代码后跟
[self.tableView reloadData];
我什么都没得到,有人知道如何解决这个问题吗?
【问题讨论】:
-
你的表格视图连接了吗?
-
我有下面的表格视图代码。 self.tableDataSource = tempArray;然后,我有代码将 plist 的 tabeDataSource 设置为 objectAtKey。该表在第一次运行时填充良好,但在应用程序运行时我无法刷新数据
-
我的意思是,您的表格视图是否与 Storyboard/IB 中的控制器等相关联?
-
是的,tableview是在interface builder的RootViewController中连接的
-
一无所获意味着tableview是空的?
标签: objective-c ios xcode uitableview plist