Guest User

Untitled

a guest
Jan 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. - (AppDataObject*) theAppDataObject
  2. {
  3. id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication sharedApplication].delegate;
  4. AppDataObject* theDataObject;
  5. theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
  6. return theDataObject;
  7. }
  8.  
  9. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  10. {
  11. tempImageString = (((championList *) [self.champions objectAtIndex:indexPath.row]).championImage);
  12.  
  13. AppDataObject *theDataObject = [self theAppDataObject];
  14. NSLog(@"tempIm-g = %@",tempImageString);
  15. theDataObject.imageString = tempImageString;
  16. NSLog(@"theAppDataObject.imageString = %@",theDataObject.imageString);
  17.  
  18. [self.navigationController popToRootViewControllerAnimated:YES];
  19. }
  20.  
  21. -(void)viewWillAppear:(BOOL)animated
  22. {
  23. AppDataObject* theDataObject = [self theAppDataObject];
  24. UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
  25. NSLog(@"temp image = %@",tempImage);
  26. [choosenChampionImageView setImage:tempImage];
  27. }
  28.  
  29. AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  30. appdelegate.imageString = tempImageString;
  31.  
  32. @interface championsListTableViewController : UITableViewController
  33. {
  34. NSString *tempImageString;
  35.  
  36. AppDataObject* theDataObject;
  37. }
  38.  
  39. @property(strong,nonatomic) NSString *tempImageString;
  40.  
  41. @property(strong,nonatomic) AppDataObject* theDataObject;
  42.  
  43. theAppDataObject.imageString = [tempImageString retain];
  44.  
  45. // this the way too declare a protocal.
  46. // .h file
  47. @protocol TestProtocol <NSObject>
  48.  
  49. -(void)testMyProtocolMethod:(NSString *)testvalue;
  50.  
  51. @end
  52.  
  53. @interface TestProtocolClass: NSObject
  54. {
  55. id <TestProtocol> delegate;
  56.  
  57. }
  58. @property (nonatomic , assign) id <TestProtocol> delegate;
  59. /* synthesize in the .m file of this class*/
  60. @end
  61.  
  62.  
  63.  
  64. //Now you have to use this protocol in any class where you want to use , Do like as:
  65. //let us suppose you want to use this protocal method in a class named "DemoProtocal".
  66. // .h file
  67. import "TestProtocol.h"
  68. @interface DemoProtocal <TestProtocol>{
  69.  
  70. }
  71. @end
  72.  
  73. //.m file
  74. #import "DemoProtocal.h"
  75. @implementation DemoProtocal
  76.  
  77. - (id)init{
  78.  
  79. TestProtocol *test = [[TestProtocol alloc]init];
  80. test.delegate = self;
  81.  
  82. }
  83.  
  84. -(void)testMyProtocolMethod:(NSString *)testvalue{
  85.  
  86. // Do appropriate things.
  87. }
  88. @end
  89.  
  90. //Declare a variable from where you want to set the value of the "AppDelegate Class".
  91. //in the yourclass.h file.
  92. AppDelegate/* this is the main class of the Application*/ *appDel;
  93.  
  94. //and initialize it where you want to use or you can initialize at the init of the class.
  95.  
  96. appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  97.  
  98. // Then set the value.
  99. appDel.imageString = tempImageString;
Add Comment
Please, Sign In to add comment