2011-09-10 47 views

回答

0

最简单的是使从数据plist文件有以下NSArrayNSDictionary格式:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <dict> 
    <key>Name 1</key> 
    <string>Description 1</string> 
    </dict> 
    <dict> 
    <key>Name 2</key> 
    <string>Description 2</string> 
    </dict> 
</array> 
</plist> 

这个文件添加到应用程序。当你要访问它,你这样做是通过

NSString *path=[[NSBundle mainBundle] pathForResource:@"MyList" ofType:@"plist"]; 
NSArray *array =[NSArray arrayWithContentsOfFile:path];OfFile:path]; 

现在你有一个包含NSDictionaries,各自有您需要为您UITableView信息的NSArray

现在您只需要使用此数组填充UITableView。通过实施这两种方法来实现这一点:

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{ 
    return [array count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Create your cells 
    NSDictionary *dict = [array objectAtIndex:indexPath.row]; 
    // use the key and description however you like in your cell 
} 
+0

非常感谢你 –

相关问题