2012-07-12 2 views
0

사용자 정의 TableView 셀인 간단한 인터페이스 작성기 파일이 있습니다. 사용자 정의의 tableview 셀은 두 개의 콘센트 ... 나는이 오류가 몇 가지 이상한 이유로사용자 정의 TableView 셀의 UIWebView

  1. 웹보기
  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) 

내 XIB있다

enter image description here

그리고 여기가

#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; 
} 

주입니다 CustomCell.h 위 XIB의 컨트롤러 ...입니다 : 인터페이스 파일에서 이것을 선언하고 사용자 정의 셀을 가져옵니다.

VPCustomCell *cell; 

이해하는데 어려움이 무엇이 문제입니까?

+0

어디에도 '셀'에 대한 선언이 없습니다. xibs 또는 스토리 보드를 사용하고 있습니까? –

+0

사용자 정의 셀에 대한 tableview 및 xib에 대한 스토리 보드 –

+0

스토리 보드 내에서 사용자 정의 셀을 구현할 수 있습니다.이 방법은 이동하기가 훨씬 쉬우 며 'dequeueReusableCellWithIdentifier :'를 사용할 수도 있습니다. 당신이해야 할 일은 프로토 타입 컨텐츠를 사용하도록 테이블 뷰를 설정 한 다음 거기에 표시되는 셀을 사용자 정의 셀 클래스로 변경할 수 있고 거기에 웹 뷰를 삽입 할 수 있습니다. –

답변

0

을해야한다 (옵션 - 명령 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; 

그리고 당신은 Identity Inspector에서 보면, 인터페이스 빌더에서 좋은

+0

문제는'dequeueReusableCellWithIdentifier'가 커스텀 서브 클래스 대신에 디폴트'UITableViewCell'를 리턴 할 가능성이 더 큽니다. –

+1

개인적으로 코드에서 태그를 사용하는 것이 매우 지저분하고 읽기가 힘들 기 때문에 개인적으로는 결코하지 않을 것입니다.그러나 이것을하고 싶다면 적어도 코드를보다 쉽게 ​​읽을 수 있도록 태그에 상수를 사용하십시오. –

관련 문제