Эй, я работаю над приложением, которое публикует 50 мест в динамическом tableView, и когда вы нажимаете на местоположение, оно переходит к новому контроллеру tableView и публикует 50 фотографий из этого места. Я создал tableViewController, а затем создал новый файл, содержащий все файлы, которые требуются tableView IE Cellforrowatindexpath. У меня есть переход от основного tableViewcontroller, но вся информация хранится в новом файле, который содержит методы, используемые tableViewController. Нужно ли писать PrepareForSegue в tableViewController или в файле, в котором есть методы, создающие таблицу? также, если я напишу это в tableViewCOntroller, как мне получить доступ к имени ячейки для одной из ячеек, которые создаются динамически? Спасибо.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"Photos for location"]){
//I dont know what to use for the name
[segue.destinationViewController setPhotoInPlace: WHAT DO I CALL THIS!?
}
}
Имена вызовов берутся из другого файла, который использует общедоступный API для создания массива словарей, содержащих такую информацию, как имя и местоположение. Файл называется flickrFetcher. Вот код, который динамически создает ячейки. self.brain — это экземпляр flickerFetcher, а topPlaces — это метод, вызываемый из flickrFetcher для получения NSArray NSdictionaries.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
// Create an instance of the cell
UITableViewCell *cell;
cell = [self.tableView dequeueReusableCellWithIdentifier:@"Photo Description"];
if(!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Photo Description"];
// set properties on the cell to prepare if for displaying
//top places returns an array of NSDictionairy objects, must get object at index and then object for key
// the cellTitle has country then province, country goes in main title and province will go as subtitle.
NSString * cellTitle = [[[[self.brain class] topPlaces] objectAtIndex:self.location] objectForKey:@"_content"];
NSRange cellRange = [cellTitle rangeOfString:@","];
NSString * cellMainTitle = [cellTitle substringToIndex:cellRange.location];
cell.textLabel.text = cellMainTitle;
NSString* cellSubtitle = [cellTitle substringFromIndex:cellRange.location +2];
cell.detailTextLabel.text = cellSubtitle;
//location is an int property that allows a new selection when using objectAtIndex
self.location++;
return cell;
}