嘿,我正在處理一個在動態tableView中發佈50個位置的應用程序,當您點擊某個位置時,它將繼續播放到新的tableView控制器,並從該位置發佈50張照片。我創建了一個tableViewController,然後創建了一個新文件,其中包含一個tableView需要IE Cellforrowatindexpath的所有文件。我有從主tableViewcontroller連接的segue,但所有的信息都存儲在newfile中,該文件包含tableViewController使用的方法。我是否在tableViewController中編寫PrepareForSegue,或者將它寫入具有創建表的方法的文件中?如果我將它寫入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的NSArray的方法。
- (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;
}
通過新的文件我的意思是我做的一個子類它 – 2012-08-02 22:07:07
好的,如果它是一個子類,意味着它也是一個'UIViewController',所以無論你將方法放在父對象還是子對象中,都不應該產生功能差異。孩子可能會更好地訪問您想要傳遞給新控制器的信息......我猜測。 – 2012-08-02 22:10:28
當我把prepareforsegue在父母,然後寫入NSIndexPath * indexPath = [self.tableView indexPathForCell:sender];我得到一個錯誤,聲明tableview沒有被聲明。但是當它在孩子身上時,這個錯誤被清除了。如果索引路徑只返回行和段,我該如何獲得調用名稱? – 2012-08-02 22:17:09