สวัสดี ฉันกำลังทำงานกับแอปพลิเคชันที่โพสต์ตำแหน่ง 50 ตำแหน่งใน tableView แบบไดนามิก และเมื่อคุณคลิกที่ตำแหน่ง มันจะแยกไปยังตัวควบคุม tableView ใหม่และโพสต์รูปภาพ 50 รูปจากตำแหน่งนั้น ฉันสร้าง tableViewController แล้วสร้างไฟล์ใหม่ซึ่งมีไฟล์ทั้งหมดที่ tableView ต้องใช้ IE Cellforrowatindexpath ฉันมีการเชื่อมต่อต่อจาก tableViewcontroller หลัก แต่ข้อมูลทั้งหมดจะถูกเก็บไว้ในไฟล์ใหม่ซึ่งมีวิธีการที่ tableViewController ใช้ ฉันจะเขียน PreparForSegue ใน 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 สาธารณะเพื่อสร้างอาร์เรย์ของพจนานุกรมซึ่งมีข้อมูลเช่นชื่อและที่ตั้ง ไฟล์นี้มีชื่อว่า FlickerFetcher นี่คือโค้ดที่สร้างเซลล์แบบไดนามิก 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;
}