Самым простым является создание файла plist
из данных в следующем формате NSArray
и NSDictionary
:
<?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];
Теперь у вас есть NSArray
, содержащий NSDictionaries
, каждый из которых содержит информацию, необходимую для вашего UITableView
.
Все, что вам нужно сделать сейчас, это заполнить 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
}