2011-09-10 49 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

非常感謝你 –

相關問題