0
親愛的學者,代碼大師。將一個簡單的UIView從一個類添加到主ViewController中
我的問題很簡單,我一直在尋找並嘗試一段時間沒有任何運氣,我將不勝感激一些小小的幫助。
我有一個簡單的類,應該產生一個觀點如下:
// vipcardclass.h
//
#import <UIKit/UIKit.h>
@interface vipcardclass : UIViewController {
}
+(IBAction)newsletter;
@end
和
// vipcardclass.m
#import "vipcardclass.h"
@implementation vipcardclass
+(IBAction)newsletter{
UIView *vipcard = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 290.0, 280.0)];
UIImageView *vipcardBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vip_card.png"]]; //background.png
[vipcard addSubview:vipcardBG];
CGRect webFrame = CGRectMake(6.0, 0.0, 300.0, 210.0);
UIWebView *content = [[UIWebView alloc] initWithFrame:webFrame];
[content setBackgroundColor:[UIColor clearColor]];
[content setOpaque:NO];
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[content loadRequest:requestObj];
[vipcard addSubview:content];
[content release];
[???????? addSubview:vipcard];
NSLog(@"Newsletter was called");
}
@end
(請看看??????,幾行字上面,如果是我使用self.view addSubview的主視圖控制器:,我的問題是從類中使用它時的正確語法)
在我的主視圖控制器I #import「v ipcardclass.h「
並在某些時候調用類函數 [vipcardclass newsletter];
除了將它添加到主控制器之外,它工作得很好。 我會添加一個旁註,即類功能不與主視圖控制器中的任何函數進行通信或相關,它是一個消防和遺忘的事情,我只想打開並顯示此視圖。
謝謝。
解決和從在溶液 小case sensative錯誤的效果很好,除了[self.view addsubview:vipcard]; 應該是 [self.view addSubview:vipcard]; // Capital S 請改變它爲下一代看看這篇文章 謝謝你的解決方案,我很感激。 – chewy 2010-08-18 15:12:43
大聲笑,這就是我依靠自動填充得到的。 – 2010-08-18 15:17:10
嘿那裏斯蒂芬,再次感謝你擴大答案。我正在使用第一種方法,並添加了一個應該從superview中刪除此視圖的按鈕,但似乎我不能,有關語法的任何想法? (無效)closeKeyFunction:(id)發件人{ \t NSLog(@「Close VIP Card%@」,sender); \t // [self.view removeFromSuperview];; // - 問題在這裏 } – chewy 2010-08-19 00:39:49