2012-07-12 60 views
0

我有一個簡單的Interface Builder文件,它是一個Custom TableView Cell。自定義的tableview單元有兩個網點...在自定義TableView Cell中的UIWebView

  1. 的WebView
  2. 文本標籤

出於某種奇怪的原因,我得到這個錯誤...

2012-07-12 16:28:23.206 VideoPush[3761:707] -[UITableViewCell webView]: unrecognized selector sent to instance 0x168cc0 
2012-07-12 16:28:23.211 VideoPush[3761:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell webView]: unrecognized selector sent to instance 0x168cc0' 
*** First throw call stack: 
(0x355e188f 0x37988259 0x355e4a9b 0x355e3915 0x3553e650 0x87279 0x33075efb 0x33074fd9 0x33074763 0x33018f37 0x355401fb 0x32410aa5 0x324106bd 0x32414843 0x3241457f 0x3243c911 0x3243c8e3 0x3305a10f 0x33047b33 0x33015ac3 0x33015567 0x33014f3b 0x371d422b 0x355b5523 0x355b54c5 0x355b4313 0x355374a5 0x3553736d 0x3304686b 0x33043cd5 0x86e5b 0x86e00) 
terminate called throwing an exception(lldb) 

MY XIB

enter image description here

這裏是CustomCell.h上述廈門國際銀行的控制器......

#import <UIKit/UIKit.h> 

@interface VPCustomCell : UITableViewCell 
@property (strong, nonatomic) IBOutlet UIWebView *webView; 
@property (strong, nonatomic) IBOutlet UILabel *titleLabel; 

@end 

最後是包含實際表視圖我的視圖控制器...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    NSString *htmlString = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 120\"/></head> <body style=\"background:#FFF;margin-top:0px;margin-left:0px\"> <div><object width=\"120\" height=\"80\"> <param name=\"movie\" value=\"http://www.youtube.com/v/1Xqn5IHbusA&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param> <param name=\"wmode\" value=\"transparent\"></param> <embed src=\"http://www.youtube.com/v/1Xqn5IHbusA&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"120\" height=\"80\"></embed> </object></div></body></html>"; 
    // Configure the cell... 
    [cell.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]]; 
    cell.titleLabel.text = @"Hello"; 

    return cell; 
} 

注意:在接口文件中,我聲明瞭這一點並導入了我的自定義單元格...

VPCustomCell *cell; 

我有什麼麻煩理解是錯誤是什麼問題?

+0

你沒有在任何地方聲明'cell'。你在使用xib還是故事板? – 2012-07-12 20:41:51

+0

用於tableview和xib的自定義單元格的故事板 – 2012-07-12 20:42:36

+0

您可以在故事板中實現自定義單元格,這將是一個更簡單的方法,它還允許您使用'dequeueReusableCellWithIdentifier:'。所有你需要做的就是設置你的tableview使用原型內容,然後在那裏顯示的單元格可以更改爲你的自定義單元類,然後插入webview – 2012-07-12 20:43:49

回答

0

在Interface Builder中,看在身份檢查(選項命令-3),並確保你已經設置了類表格的爭奪細胞到您的CustomCell細胞類。

-3

使用UITableViewCells時,最好處理標籤而不是插座。對於你的問題,我會刪除網點,在屬性檢查器中給Webview一個標籤或任何你想要的,比如100.對標籤做同樣的事情。然後在您的cellForRowAtIndexPath:

static NSString *CellIdentifier = @"Cell"; 
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

NSString *htmlString = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 120\"/></head> <body style=\"background:#FFF;margin-top:0px;margin-left:0px\"> <div><object width=\"120\" height=\"80\"> <param name=\"movie\" value=\"http://www.youtube.com/v/1Xqn5IHbusA&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param> <param name=\"wmode\" value=\"transparent\"></param> <embed src=\"http://www.youtube.com/v/1Xqn5IHbusA&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"120\" height=\"80\"></embed> </object></div></body></html>"; 
// Configure the cell... 
UIWebView *thisWebView = (UIWebView*)[cell viewWithTag:100]; 
UILabel *thisLabel = (UILabel*)[cell viewWithTag:whateverYouWant]; 
[thisWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]]; 
thisLabel.text = @"Hello"; 
return cell; 

,你應該是好

+0

問題更可能是'dequeueReusableCellWithIdentifier'返回默認的'UITableViewCell'而不是自定義子類 – 2012-07-12 20:52:11

+1

個人而言,我絕不會這樣做,因爲在代碼中使用標記會使其非常混亂且難以閱讀。但是,如果你確實想這樣做,至少使用標籤的常量,因爲它會使代碼更清晰。 – 2012-07-12 21:01:02