ちょっと私は、動的なtableViewに50の場所を投稿するアプリケーションに取り組んでおり、場所をクリックすると、新しいtableViewコントローラーに移動し、その場所から50の写真を投稿します。tableViewController を作成してから、tableView が IE Cellforrowatindexpath に必要とするすべてのファイルを含む新しいファイルを作成しました。メインのtableViewcontrollerから接続するセグエがありますが、すべての情報はtableViewControllerが使用するメソッドを含むnewfileに保存されます。tableViewController に PrepareForSegue を記述しますか、それともテーブルを作成するメソッドを含むファイルに記述しますか? また、tableViewCONtroller に記述した場合、動的に作成されたセルの 1 つのセル名にアクセスするにはどうすればよいですか? ありがとう。
-(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 は NSdictionaries の NSArray を取得するために flickrFetcher から呼び出されるメソッドです。
- (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;
}