MasterViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // RootViewController.m
  3. // SVGPad
  4. //
  5. // Copyright Matt Rajca 2010-2011. All rights reserved.
  6. //
  7. #import "MasterViewController.h"
  8. #import "DetailViewController.h"
  9. @interface MasterViewController()
  10. @property(nonatomic,strong) NSString* nameOfBrokenSVGToLoad;
  11. @end
  12. @implementation MasterViewController
  13. @synthesize sampleNames = _sampleNames;
  14. @synthesize detailViewController = _detailViewController;
  15. @synthesize nameOfBrokenSVGToLoad = _nameOfBrokenSVGToLoad;
  16. - (void)setupSampleNames
  17. {
  18. self.sampleNames = [NSMutableArray arrayWithObjects: @"map-alaska-onlysimple", @"g-element-applies-rotation", @"groups-and-layers-test", @"http://upload.wikimedia.org/wikipedia/commons/f/f9/BlankMap-Africa.svg", @"shapes", @"strokes", @"transformations", @"rounded-rects", @"gradients",@"radialGradientTest", @"PreserveAspectRatio", @"australia_states_blank", @"Reinel_compass_rose", @"Monkey", @"Blank_Map-Africa", @"opacity01", @"Note", @"Note@2x", @"heart", @"M-to-S-to-T", @"imageWithASinglePointPath", @"Lion", @"lingrad01", @"Map", @"CurvedDiamond", @"Text", @"text01", @"tspan01", @"Location_European_nation_states", @"uk-only", @"Europe_states_reduced", @"Compass_rose_pale", @"quad01", @"cubic01", @"rotated-and-skewed-text", @"RainbowWing", @"sakamura-default-fill-opacity-test", @"StyleAttribute", @"voies", @"nil-demo-layered-imageview", @"svg-with-explicit-width", @"svg-with-explicit-width-large", @"svg-with-explicit-width-large@160x240", @"BlankMap-World6-Equirectangular", @"Coins", @"parent-clip", @"CSS", @"imagetag-layered", @"ImageAspectRatio", @"test-stroke-dash-array", @"radial-gradient-opacity", @"radgrad01", @"pattern01", @"Mozilla_Firefox_logo_2013",
  19. // This file is still not fully supported, arc to is missing, but it has the evenodd in it
  20. @"fillrule-evenodd",
  21. nil];
  22. }
  23. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  24. {
  25. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  26. if (self) {
  27. [self setupSampleNames];
  28. }
  29. return self;
  30. }
  31. - (id)initWithCoder:(NSCoder *)aDecoder {
  32. self = [super initWithCoder:aDecoder];
  33. if (self) {
  34. [self setupSampleNames];
  35. }
  36. return self;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.clearsSelectionOnViewWillAppear = NO;
  41. self.preferredContentSize = CGSizeMake(320.0f, 600.0f);
  42. }
  43. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  44. return YES;
  45. }
  46. - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
  47. return [_sampleNames count];
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  50. static NSString *CellIdentifier = @"Cell";
  51. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  52. if (!cell) {
  53. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  54. reuseIdentifier:CellIdentifier];
  55. }
  56. cell.textLabel.text = [_sampleNames objectAtIndex:indexPath.row];
  57. return cell;
  58. }
  59. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  60. {
  61. if( [[_sampleNames objectAtIndex:indexPath.row] isEqualToString:@"Reinel_compass_rose"])
  62. {
  63. NSLog(@"*****************\n* WARNING\n*\n* The sample 'Reinel_compass_rose' is currently unsupported;\n* it is included in this build so that people working on it can test it and see if it works yet\n*\n*\n*****************");
  64. [[[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Reinel_compass_rose breaks SVGKit, it uses unsupported SVG commands; until we have added support for those commands, it's here as a test - but it WILL CRASH if you try to view it" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK, crash",nil] show];
  65. self.nameOfBrokenSVGToLoad = [_sampleNames objectAtIndex:indexPath.row];
  66. return;
  67. }
  68. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  69. if (!self.detailViewController) {
  70. self.detailViewController = [[DetailViewController alloc] initWithNibName:@"iPhoneDetailViewController" bundle:nil];
  71. }
  72. [self.navigationController pushViewController:self.detailViewController animated:YES];
  73. self.detailViewController.detailItem = [_sampleNames objectAtIndex:indexPath.row];
  74. } else {
  75. self.detailViewController.detailItem = [_sampleNames objectAtIndex:indexPath.row];
  76. }
  77. }
  78. #pragma mark - alertview delegate
  79. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  80. {
  81. if( buttonIndex == [alertView cancelButtonIndex] )
  82. {
  83. return;
  84. }
  85. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
  86. if (!self.detailViewController) {
  87. self.detailViewController = [[DetailViewController alloc] initWithNibName:@"iPhoneDetailViewController" bundle:nil];
  88. }
  89. [self.navigationController pushViewController:self.detailViewController animated:YES];
  90. self.detailViewController.detailItem = self.nameOfBrokenSVGToLoad;
  91. } else {
  92. self.detailViewController.detailItem = self.nameOfBrokenSVGToLoad;
  93. }
  94. self.nameOfBrokenSVGToLoad = nil;
  95. }
  96. @end