2012-08-06 1 views
0

이 내 예입니다 :이 같은 방법을 가지고 같은이 변수 Class 객체 선언을 가지고 추적 할 수없는 가망입니다

UITableView *cell = [[MyCustomClass alloc] init]; 

내가 제공자 라이선스 계약 "MyCustomClass을"변화 할 수 있음을 어떻게든지 그것을 할 수있는 방법이 있나요 :

-(NSObject*)newMethod:(int)intNumber{ 
classVariable = someClass depending on intNumber 
UITableView *cell [[<<<classVariable>>> alloc] init]; 
return cell; 
} 

나는 내가 올바른 정의 세포를 만들 수 있습니다, 그리고 내 옆에 구현하는 글로벌 방법으로 그것을 사용하기 때문에이 방법을 원하는이 내가 여기에 유래 다른 질문 (사용 발견 사용하는 코드입니다 xib에서 사용자 정의 셀로드) :

이되는 모든 문제가

이 실제로 내 친구도 원 -210

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:stringIdentifier]; 

if (cell == nil) { 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; 
    for (id currentObject in nib) { 
     if ([currentObject isKindOfClass:[UITableViewCell class]]) { 
      cell = (MyClassCell*) currentObject; 
      break; 
     } 
    } 
    cell = (MyClassCell *)[nib objectAtIndex:0]; 
} 

내 목표는 내가 모든 정보를 요구 위의 코드를 전송하는 방법 느릅 나무을하는 것입니다, 느릅 나무는 tableViw, stringidentifier, nibName 및 MyClassCell <입니다 자신의 구현에 사용하기 위해이 문제를 해결하는 방법을 알고, 우리는 이것에 대한 단서에 대해 매우 감사 할 것입니다, 미리 감사드립니다!

답변

0

당신은 class를 사용하여 클래스의 Class를 얻을 수 있습니다 :

Class myclass = [MYClass class]; 

은 이제 변수로 주위 myclass를 전달할 수 있습니다, 그리고 당신은 Class이 필요한 곳에서 사용할 수 있습니다 :

id myinstance = [[myclass alloc] init]; 
0

NSArray에 클래스 이름이나 클래스를 배치하여 색인을 사용할 수 있습니다.

NSArray *classes = [NSArray arrayWithObjects:[ClassOne class], [ClassTwo class], [C 

assThree class], Nil];

id instance = [[(Class)[classes objectAtIndex:anIndex] alloc] init]; 

동적 런타임시/사용 클래스 정보를 구성하고자하는 경우, 당신은 NSClassFromString() 함수를 사용할 수 있습니다

id anObject = [[NSClassFromString(@"FooBar") alloc] init];