ios - UIScrollView cannot call addSubview for another UIViewController -


i have 3 controller

  1. first controller load list data (success) --> searchviewcontroller

  2. second controller load detail content ozdetailtestviewcontroller in third controller --> ozdetailsearchviewcontroller

  3. third controller --> ozdetailtestviewcontroller

my problem is, when call function in ozdetailsearchviewcontroller (createviewatindex) uiscrollviewcontroller cannot load, log print when nslog in ozdetailtestviewcontroller. think _scrolldetailnews cannot alloc, don't know how alloc that.

this code:

ozdetailsearchviewcontroller.h

@interface ozdetailsearchviewcontroller : uiviewcontroller<uiwebviewdelegate, uiscrollviewdelegate> @property (strong, nonatomic) iboutlet uiscrollview *scrolldetailnews; @property (strong, nonatomic) iboutlet uiview *viewforscroll; @property (strong, nonatomic) iboutlet uilabel *lbllinekanal; @property (strong, nonatomic) iboutlet uiimageview *imgheader;  @property (strong, nonatomic) iboutlet nsarray *arrallnews;  @property int indexpagenews; @property nsuinteger idnewskanal; @end 

ozdetailsearchviewcontroller.m

- (void)viewdidload {     [super viewdidload];     _lbllinekanal.backgroundcolor = [uicolor colorwithred:20/255.0 green:130/255.0 blue:255/255.0 alpha:1.0];      _currentindex = _indexpagenews;     gcpagedscrollview* scrollview = [[gcpagedscrollview alloc] initwithframe:cgrectmake(0, 80, self.view.frame.size.width, 954)];     scrollview.delegate = self;     self.scrollview.backgroundcolor = [uicolor whitecolor];     (nsuinteger index = 0; index < _arrallnews.count; index ++) {         //you add content views here         [scrollview addcontentsubview:[self createviewatindex:index]];      }      [self.view addsubview:scrollview];     [scrollview setpage:_indexpagenews animated:yes];     // additional setup after loading view nib. }  - (uiview *)createviewatindex:(nsuinteger)index {     boxdetailtest = [[ozdetailtestviewcontroller alloc]initwithnibname:@"ozdetailtestviewcontroller" bundle:nil];     _scrolldetailnews = [[uiscrollview alloc] initwithframe:cgrectmake(0.0, 107.0, 320.0, 415.0)];     [_scrolldetailnews setcontentsize:cgsizemake(320.0, 463.0)];     [_scrolldetailnews addsubview:boxdetailtest.view];     _scrolldetailnews.delegate = self;     [boxdetailtest test:index];     return boxdetailtest.view; } 

ozdetailtestviewcontroller.h

@interface ozdetailtestviewcontroller : uiviewcontroller -(void)test:(nsuinteger)index;  @end 

ozdetailtestviewcontroller.m

#import "ozdetailtestviewcontroller.h"  @interface ozdetailtestviewcontroller ()  @end  @implementation ozdetailtestviewcontroller  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view nib. }  -(void)test:(nsuinteger)index{     nslog(@"%@",@"sini");     uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 100, 20)];     label.text = [nsstring stringwithformat:@"test %u", index]; }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  @end 

you have iboutlet scrolldetailnews assume must have created scroll view in storyboard/xib. again overriding same variable (_ scrolldetailnews) in createviewatindex method not adding main view. remove line

_scrolldetailnews = [[uiscrollview alloc] initwithframe:cgrectmake(0.0, 107.0, 320.0, 415.0)]; 

and instead use self.scrolldetailnews. if want change frame of scroll view directly that:

cgrect newframe=cgrectmake(0,0,0,0); //fill in correct values self.scrolldetailnews.frame = newframe; 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -