Hai, saya sedang mengerjakan aplikasi yang memposting 50 lokasi dalam tableView dinamis dan ketika Anda mengklik suatu lokasi, aplikasi itu akan berpindah ke pengontrol tableView baru dan memposting 50 foto dari lokasi itu. Saya membuat tableViewController dan kemudian membuat file baru yang berisi semua file yang diperlukan tableView IE Cellforrowatindexpath. Saya memiliki koneksi segue dari tableViewcontroller utama tetapi semua informasi disimpan di file baru yang berisi metode yang digunakan tableViewController. Apakah saya menulis PrepareForSegue di tableViewController atau menulisnya di file yang memiliki metode untuk membuat tabel? juga jika saya menulisnya di tableViewCONtroller bagaimana cara mengakses nama sel untuk salah satu sel yang dibuat secara dinamis? terima kasih.
-(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!?
}
}
Nama panggilan berasal dari file lain yang menggunakan API publik untuk membuat serangkaian kamus yang memiliki informasi seperti nama dan lokasi. File tersebut bernama flickrFetcher. Berikut adalah kode yang membuat sel secara dinamis. self.brain adalah turunan dari flickFetcher dan topPlaces adalah metode yang dipanggil dari flickrFetcher untuk mendapatkan NSArray dari 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;
}