2011-11-01 5 views
2

에 내 사용자 지정 셀의 IBOutlets에 액세스 할 수 없습니다 이 방법은 다음 D에 cell.tweetText.text = [tweets objectAtIndex:indexPath.row];은 cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 
    TWCustomCell *cell = (TWCustomCell*)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    //UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"TWCustomCell" owner:nil options:nil]; 

     for (id currentObject in topLevelObject) { 
      if([currentObject isKindOfClass:[UITableViewCell class]]) { 
       cell = (TWCustomCell*) currentObject; 
       break; 
      } 
     } 
    } 
    // Configure the cell... 
    cell.tweetText.text = [tweets objectAtIndex:indexPath.row]; 
    return cell; 
} 

Xcode는 cell 이후에 'TWCustomCell *'유형의 객체에서 'tweetText'속성을 찾을 수 없습니다. tweetText '에 액세스하려고 했습니까? "라고 묻고, cell->tweetText.text으로 바꾸라고 알려줍니다."시맨틱 문제 : 인스턴스 변수'tweetText '가 보호되어 있습니다. "

답변

1

문제는 내 사용자 정의 셀 인스턴스 변수와이었다. 당신은 도트 구문을 사용하여 클래스의 외부 IBOutlets에 대한 액세스를 허용하는 속성을 선언하지 않았다

#import <UIKit/UIKit.h> 

@interface TWCustomCell : UITableViewCell { 
    //added here @public and you can access them now 
    @public 
    IBOutlet UILabel *nick; 
    IBOutlet UITextView *tweetText; 
} 

@end 
+0

당신을 – Basel

+1

다른 객체의 인스턴스 변수를 쓰레기와 janky입니다. 그것들을'@ public'으로 선언하는 것은 좋은 이유 때문에 디폴트로 비활성화되어있는 것을 활성화시키는 반창고입니다. 대신 ('@ property')를 선언하고 대신에 속성 ('.'이 아니라'-')을 사용해야합니다. –

2

다음

내가 그것을 할 것입니다 방법 :

i n은 당신의 .H 파일 다음하는 .m에서

@property (nonatomic, readonly) UILabel *nick; 
@property (nonatomic, readonly) UITextView *tweetText; 

:

@synthesize nick, tweetText; 

아니면 바르의 IBOutlets를 제거하고이 같은 유지로 특성과 IBOutlets 선언 할 수 :

@property (nonatomic, retain) IBOutlet UILabel *nick; 
@property (nonatomic, retain) IBOutlet UITextView *tweetText; 
+0

오류가 발생합니다 : "의미 론적 문제 : 인스턴스 변수 'tweetText'가이를 다시 할 때 보호되지만, '@ public'을 사용하지 않을 때 – pmerino

+0

@ zad0xsis". "를 사용해야합니다. "->"대신 "->"를 입력하면됩니다. 속성을 사용하는 관례는 관습에 어긋나는 공개 ivars ("->"포함) 액세스입니다. –

관련 문제