开发者

Getting data from tableviewcell to 2nd view

I am very new to this and am trying to learn by creating a few little apps for myself. I have a navigation-based app where the user taps the row to select a film title - I then want the second view to show details of the film.

Thanks to a very helpful person here I am getting the results of the row pressed as 'rowTitle' as follows :

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = [keys objectAtIndex:indexPath.section];
NSArray *nameSection = [names objectForKey:key];
NSString *rowTitle = [nameSection objectAtIndex:indexPath.row];
NSLog(@"rowTitle = %@", rowTitle);
[tableView deselectRowAtIndexPath:indexPath animated:YES];

I am, however, struggling to make the data at 'rowTitle' available to the 2nd view -

Basically, if I can get the info - for example rowTitle is "aliens2" - I want to be able to add a new extension to the end of the string returned by 'rowTitle' in order to point to an image (if that makes sense) in the second view...

Something like

tempImageName=[** this is where the info from rowTitle needs to be I suppose**]; tempImageType=@".png"; finalImageNa开发者_JAVA技巧me=[tempImageName stringByAppendingString:tempImageType];

Does this make sense to anyone (apologies if it doesnt - I know what I want but how to explain it is a little more awkward!)


You should use stringByAppendingPathExtension to add the png extension, if you really need to do that. But that depends on what you are going to do with it; you may not need the full file name just to just a file, for instance - pathForResource:ofType: can take the extension as the type argument (but imageNamed: likes the full filename).

You should add a property in your second view controller for the image name, then create and push/present the view controller in your select method.

MyViewController *vc = [[MyViewController alloc] init];
vc.imageName = tempImageName;
[self.navigationController pushViewController:vc animated:YES];
[vc release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜