Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
iOS Development
How can I call another viewController through an event?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="lftapajos" data-source="post: 1364279" data-attributes="member: 236622"><p>HELP !!!!</p><p></p><p>My question is as follows:</p><p></p><p>I have a ScrollViewer where I programmatically create buttons and add them images. These buttons have the appearance of images created randomly.</p><p></p><p>To find out which button I clicked, I use:</p><p></p><p>######################################</p><p></p><p>for (int i = 1, i <7; i + +)</p><p>{</p><p>UIButton * button = [[UIButton buttonWithType: UIButtonTypeCustom] retain];</p><p>********botao.frame CGRectMake = ((i-1) * 199, 0, 199, 169);</p><p>********botao.backgroundColor = [UIColor whiteColor];</p><p>********[botao setBackgroundImage: [UIImage imageNamed: [NSString stringWithFormat: @ "image% d.jpg", i]] forState: UIControlStateNormal];</p><p></p><p>********botao.tag = i;</p><p></p><p>[botao addTarget:self action<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" /> selector(callNextViewController<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> forControlEvents: UIControlEventTouchUpInside];</p><p></p><p>[botao release];</p><p>}</p><p></p><p>######################################</p><p></p><p></p><p>So I call a function by clicking the button:</p><p></p><p>********[botao addTarget:self action<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite4" alt=":mad:" title="Mad :mad:" loading="lazy" data-shortname=":mad:" />selector(callNextViewController<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> forControlEvents: UIControlEventTouchUpInside];</p><p></p><p></p><p></p><p>And then this function is to identify the click and call another view controller:</p><p></p><p>######################################</p><p></p><p># Import "NextViewController.h"</p><p></p><p>- (IBAction) callNextViewController: (id) sender</p><p>{</p><p>****UIButton *clicked = (UIButton *) sender;</p><p>****NSLog (@"Click in No. %d", clicked.tag);</p><p>****</p><p>****NextViewController *nextViewController = [[NextViewController alloc] init];</p><p>****nextViewController.propTypeInt clicked.tag = / / 1,2,3,4 ...</p><p>****[NextViewController setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];</p><p>****[Self presentModalViewController: nextViewController animated: YES];</p><p>}</p><p></p><p>######################################</p><p></p><p></p><p>The problem is that when I run the application and I click on the button, the next view is imported, there is a horizontal flip, and apparently the next view is called. But the screen IS DARK. As none of the objects on the screen is displayed. As if everything had gone.</p><p></p><p>ALL OBJECTS DISAPPEAR…</p><p></p><p>I put in some NSLogs "nextViewController" as to whether the "NextViewController" is being called. And it is ok! It works! </p><p></p><p>The problem is that everything is loaded, but no object is displayed on the screen.</p><p></p><p>NOTE: I have other calls to the "nextViewController" running through "Segue". But in this case, the buttons are created dynamically, I can not create "Segue" to this.</p><p></p><p>What can I do to make the objects of "nextViewController" does not disappear when I load the "nextViewController" by the "callNextViewColler"?</p></blockquote><p></p>
[QUOTE="lftapajos, post: 1364279, member: 236622"] HELP !!!! My question is as follows: I have a ScrollViewer where I programmatically create buttons and add them images. These buttons have the appearance of images created randomly. To find out which button I clicked, I use: ###################################### for (int i = 1, i <7; i + +) { UIButton * button = [[UIButton buttonWithType: UIButtonTypeCustom] retain]; ********botao.frame CGRectMake = ((i-1) * 199, 0, 199, 169); ********botao.backgroundColor = [UIColor whiteColor]; ********[botao setBackgroundImage: [UIImage imageNamed: [NSString stringWithFormat: @ "image% d.jpg", i]] forState: UIControlStateNormal]; ********botao.tag = i; [botao addTarget:self action:@ selector(callNextViewController:) forControlEvents: UIControlEventTouchUpInside]; [botao release]; } ###################################### So I call a function by clicking the button: ********[botao addTarget:self action:@selector(callNextViewController:) forControlEvents: UIControlEventTouchUpInside]; And then this function is to identify the click and call another view controller: ###################################### # Import "NextViewController.h" - (IBAction) callNextViewController: (id) sender { ****UIButton *clicked = (UIButton *) sender; ****NSLog (@"Click in No. %d", clicked.tag); **** ****NextViewController *nextViewController = [[NextViewController alloc] init]; ****nextViewController.propTypeInt clicked.tag = / / 1,2,3,4 ... ****[NextViewController setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal]; ****[Self presentModalViewController: nextViewController animated: YES]; } ###################################### The problem is that when I run the application and I click on the button, the next view is imported, there is a horizontal flip, and apparently the next view is called. But the screen IS DARK. As none of the objects on the screen is displayed. As if everything had gone. ALL OBJECTS DISAPPEAR… I put in some NSLogs "nextViewController" as to whether the "NextViewController" is being called. And it is ok! It works! The problem is that everything is loaded, but no object is displayed on the screen. NOTE: I have other calls to the "nextViewController" running through "Segue". But in this case, the buttons are created dynamically, I can not create "Segue" to this. What can I do to make the objects of "nextViewController" does not disappear when I load the "nextViewController" by the "callNextViewColler"? [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
iOS Development
How can I call another viewController through an event?
Top