Two Problems I'm having with UIButton and UIView.
Posted
by Andy
on Stack Overflow
See other posts from Stack Overflow
or by Andy
Published on 2010-04-10T17:06:33Z
Indexed on
2010/04/10
17:13 UTC
Read the original article
Hit count: 260
Hi all,
I haven't been programming on the iPhone for very long, but I'm picking it up slowly by googling problems I get. Unfortunately I haven't been able to find an answer for these.
I have started a new View-based application in Xcode 3.2.2 and immediately added the following files: myUIView.m and myUIView.h, which are subclasses of UIView. In Interface Builder, I set the subclass of the default UIView to be myUIView.
I made a button in the drawRect method.
Problem one: The title of the button only appears AFTER I click the screen, why?
Problem two: I want the button to produce the modalview - is this possible?
The code is as follow:
#import "myUIView.h"
@implementation myUIView
- (void)drawRect:(CGRect)rect {
// Drawing code
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,100,100);
[button setTitle:@"butty" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
-(void)buttonPressed:(id)sender{
NSLog(@"Button pressed");
//present modal view somehow..?
}
I can't see how to post attachments, but if anyone thinks it will help I can upload the source.
Many thanks, Andy
© Stack Overflow or respective owner