2012-08-02 32 views
1

嘿,我正在处理一个在动态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; 
} 

回答

1

prepareForSegue:UIViewController的方法,所以它需要在视图控制器。 sender参数应该是导致segue的您的单元格。您可以使用表格视图方法indexPathForCell:来获取相关的索引路径,并且在执行cellForRowAtIndexPath:时应该足以找到放入单元格的相同数据。

(我不知道你所说的“新文件”或什么类它实现的意思,因此,如果这会影响什么,我不能说。)

+0

通过新的文件我的意思是我做的一个子类它 – 2012-08-02 22:07:07

+0

好的,如果它是一个子类,意味着它也是一个'UIViewController',所以无论你将方法放在父对象还是子对象中,都不应该产生功能差异。孩子可能会更好地访问您想要传递给新控制器的信息......我猜测。 – 2012-08-02 22:10:28

+0

当我把prepareforsegue在父母,然后写入NSIndexPath * indexPath = [self.tableView indexPathForCell:sender];我得到一个错误,声明tableview没有被声明。但是当它在孩子身上时,这个错误被清除了。如果索引路径只返回行和段,我该如何获得调用名称? – 2012-08-02 22:17:09