【发布时间】:2010-04-10 17:06:33
【问题描述】:
我很久没有在 iPhone 上编程了,但我通过谷歌搜索遇到的问题慢慢掌握了它。不幸的是,我无法找到这些问题的答案。
我在 Xcode 3.2.2 中启动了一个新的基于 View 的应用程序,并立即添加了以下文件:myUIView.m 和 myUIView.h,它们是 UIView 的子类。在 Interface Builder 中,我将默认 UIView 的子类设置为 myUIView。
我在drawRect方法中做了一个按钮。
问题一:按钮的标题只有在我点击屏幕后才会出现,为什么?
问题二:我希望按钮生成模态视图 - 这可能吗?
代码如下:
#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..?
}
我看不到如何发布附件,但如果有人认为这会有所帮助,我可以上传源代码。
非常感谢, 安迪
【问题讨论】:
标签: iphone uiview uiimage modal-dialog